1// Text's glyphs: each rasterized once per face, glyph, size and quarter2// pixel of x position (pkg::alloy::text, F4 question 2), kept in pages3// of their own: outlines' coverage in one-channel pages, color glyphs'4// premultiplied RGBA (F10's emoji) in four-channel ones, drawn at whole5// pixels in their own colors. A page is cut into 16 plots, each packed6// in shelves, stamped with the frame it last gave a glyph and listing7// the keys of the glyphs it holds (F14c). A glyph goes into the most8// recently used plot of its format with room, else an empty one, else a9// new page while the format's budget allows, else the least recently10// used plot the frame being drawn has not used, cleared. A frame needing11// more than the budget gets pages past it, which are emptied first and12// released once empty. What drew from a cleared plot stays in the kept13// texture, and the frames to come pack its glyphs anew as they draw them.1415import std::vector;16import std::option;17import std::map;18import std::math;19import pkg::alloy::gpu;20import pkg::alloy::text;2122import draw;23import atlas;24import frame;2526pub const ACROSS: u32 = 4; // plots across a page, and down27pub const PLOTS: u64 = 16; // a page's28pub const MAX_MARKS: u64 = 8192; // entries of glyphs with no pixels, or tinted, before they are forgotten2930// A glyph's pixels in the cache.31pub type CachedGlyph = struct {32 pub page: u32,33 pub plot: u32,34 pub region: Rect, // in the page's pixels35 pub left: i32,36 pub top: i32,37 pub color: bool, // premultiplied RGBA, in its own colors38};3940// What the cache knows of a glyph at a size and shift.41pub type GlyphEntry = enum {42 Empty, // no pixels43 Placed: CachedGlyph,44 // a color glyph showing the text's color: one for each color, in45 // `tinted` under its key at shift 046 Tinted,47};4849// A color glyph drawn in a text's color, packed as a u32 (`packed`).50pub type Tint = struct {51 pub color: u32,52 pub glyph: Option<CachedGlyph>,53};5455// A part of a page, its glyphs packed in shelves.56pub type Plot = struct {57 pub shelves: Shelves,58 pub used: u64, // the frame it last gave a glyph59 pub keys: Vector<u64>, // of the glyphs placed in it, some placed elsewhere since60};6162pub fn Plot::empty() -> Plot => Plot {63 .shelves = Shelves::empty(),64 .used = 0,65 .keys = Vector<u64>::empty()66};6768// What a page of the cache holds.69pub type PageKind = enum {70 Plots, // 16 plots of glyphs71 Large, // a glyph larger than a plot, in a texture of its own, as its first plot72 Released, // nothing: a slot for the next page73};7475pub type GlyphPage = struct {76 pub texture: Texture,77 pub kind: PageKind,78 pub plots: Vector<Plot>, // 16, or a large glyph's one79 pub past: bool, // past the budget: emptied first, released once empty80 pub weight: u32, // the plots of the budget it takes81};8283pub type GlyphCache = struct {84 pub entries: Map<u64, GlyphEntry>,85 pub tinted: Map<u64, Vector<Tint>>,86 pub pages: Vector<GlyphPage>, // a released page's slot taken by the next87 pub budget: GlyphBudget,88 pub marks: u64, // Empty and Tinted entries made since they were last forgotten89 pub most_marks: u64, // MAX_MARKS, less in tests90 pub rasterized: u32, // glyphs, by the frame being drawn91 pub cleared: u32, // plots, by the frame being drawn92};9394pub fn GlyphCache::create() -> GlyphCache {95 return GlyphCache {96 .entries = Map<u64, GlyphEntry>::empty(),97 .tinted = Map<u64, Vector<Tint>>::empty(),98 .pages = Vector<GlyphPage>::empty(),99 .budget = GlyphBudget {},100 .marks = 0,101 .most_marks = MAX_MARKS,102 .rasterized = 0,103 .cleared = 0104 };105}106107// A glyph at a size in device pixels, a quarter of a pixel of x shift.108pub fn glyph_key(face: u32, glyph: u32, size: f32, quarter: u32) -> u64 {109 const q = min(floor(size * 4.0 + 0.5), 65535.0) to u64;110 return (face to u64 << 44) | (glyph to u64 << 20) | (q << 2) | quarter to u64;111}112113// The color as four bytes, to tell tints apart.114fn packed(c: &Color) -> u32 {115 const byte = (v: f32) => (clamp(v, 0.0, 1.0) * 255.0 + 0.5) to u32;116 return (byte(c.r) << 24) | (byte(c.g) << 16) | (byte(c.b) << 8) | byte(c.a);117}118119// The glyph's place in the cache, rasterized and packed the first time;120// None when it has no pixels. `color` is the text's, which only a color121// glyph showing it takes.122pub fn glyph(123 self cache: &var GlyphCache,124 device: &var Device,125 fonts: &Fonts,126 face: u32,127 glyph: u32,128 size: f32,129 quarter: u32,130 color: &Color,131 frame: u64132) -> Option<CachedGlyph> {133 const key = glyph_key(face, glyph, size, quarter);134 if (cache.entries.try_get(&key) is ::Some |&found|) {135 match (found) {136 ::Empty {137 return ::None;138 }139 ::Placed |cached| {140 cache.pages.get_var(141 cached.page to u64142 ).plots.get_var(cached.plot to u64).used = frame;143 return ::Some(cached);144 }145 ::Tinted {146 return cache.tint(&var device, &fonts, face, glyph, size, &color, frame);147 }148 }149 }150 // a color glyph is drawn whole pixels apart, its shift 0's for every151 // shift152 if (quarter != 0 && fonts.is_color(face, glyph)) {153 const found = cache.glyph(&var device, &fonts, face, glyph, size, 0, &color, frame);154 const whole = glyph_key(face, glyph, size, 0);155 if (cache.entries.try_get(&whole) is ::Some |&entry|) {156 cache.remember(key, copy entry);157 }158 return found;159 }160 cache.rasterized += 1;161 const image = fonts.glyph_image(162 face,163 glyph,164 floor(size * 4.0 + 0.5) / 4.0,165 quarter to f32 * 0.25,166 TextColor { .r = color.r, .g = color.g, .b = color.b, .a = color.a }167 );168 match (image) {169 ::Coverage |&mask| {170 const placed = cache.place(171 &var device,172 TextureFormat::R8Unorm,173 mask.width,174 mask.height,175 &mask.coverage.view(),176 frame177 );178 if (placed is ::Some |p|) {179 const cached = CachedGlyph {180 .page = p.page,181 .plot = p.plot,182 .region = p.region,183 .left = mask.left,184 .top = mask.top,185 .color = false186 };187 cache.remember(key, GlyphEntry::Placed(cached));188 return ::Some(cached);189 }190 cache.remember(key, GlyphEntry::Empty);191 return ::None;192 }193 ::Color |&c| {194 const placed = cache.place_color(&var device, &c, frame);195 if (c.foreground) {196 cache.remember(key, GlyphEntry::Tinted);197 cache.add_tint(key, Tint { .color = packed(&color), .glyph = placed });198 } else {199 cache.remember(200 key,201 if (placed is ::Some |p|) GlyphEntry::Placed(p) else GlyphEntry::Empty202 );203 }204 return placed;205 }206 }207}208209// Keeps the entry under the key: a placed glyph's in its plot's keys,210// the others counted, all forgotten once too many were made.211fn remember(self cache: &var GlyphCache, key: u64, entry: GlyphEntry) {212 if (entry is ::Placed |cached|) {213 cache.pages.get_var(cached.page to u64).plots.get_var(cached.plot to u64).keys.push(key);214 } else {215 cache.marks += 1;216 if (cache.marks > cache.most_marks) {217 cache.forget_marks();218 }219 }220 cache.entries.insert(key, entry);221}222223// Forgets the entries of glyphs with no pixels, and of tinted ones with224// no tint left, found again with one lookup into their face.225fn forget_marks(self cache: &var GlyphCache) {226 var gone = Vector<u64>::empty();227 for (cache.entries.entries()) |&e| {228 // a tinted glyph's tints are under its key at shift 0229 if (230 e.value is ::Empty231 || e.value is ::Tinted232 && !cache.tinted.contains(&(e.key >> 2 << 2))233 ) {234 gone.push(e.key);235 }236 }237 for (gone.view()) |key| {238 cache.entries.remove(&key);239 }240 cache.marks = 0;241}242243fn add_tint(self cache: &var GlyphCache, key: u64, tint: Tint) {244 if (tint.glyph is ::Some |cached|) {245 cache.pages.get_var(cached.page to u64).plots.get_var(cached.plot to u64).keys.push(key);246 }247 if (cache.tinted.try_get_var(&key) is ::Some |&var tints|) {248 tints.push(tint);249 } else {250 var tints = Vector<Tint>::empty();251 tints.push(tint);252 cache.tinted.insert(key, move tints);253 }254}255256// A color glyph showing the text's color, drawn in this one the first257// time.258fn tint(259 self cache: &var GlyphCache,260 device: &var Device,261 fonts: &Fonts,262 face: u32,263 glyph: u32,264 size: f32,265 color: &Color,266 frame: u64267) -> Option<CachedGlyph> {268 const key = glyph_key(face, glyph, size, 0);269 const wanted = packed(&color);270 if (cache.tinted.try_get(&key) is ::Some |&tints|) {271 for (tints.view()) |&t| {272 if (t.color == wanted) {273 if (t.glyph is ::Some |cached|) {274 cache.pages.get_var(275 cached.page to u64276 ).plots.get_var(cached.plot to u64).used = frame;277 }278 return t.glyph;279 }280 }281 }282 cache.rasterized += 1;283 const image = fonts.glyph_image(284 face,285 glyph,286 floor(size * 4.0 + 0.5) / 4.0,287 0.0,288 TextColor { .r = color.r, .g = color.g, .b = color.b, .a = color.a }289 );290 var placed: Option<CachedGlyph> = ::None;291 if (image is ::Color |&c|) {292 placed = cache.place_color(&var device, &c, frame);293 }294 cache.add_tint(key, Tint { .color = wanted, .glyph = placed });295 return placed;296}297298fn place_color(299 self cache: &var GlyphCache,300 device: &var Device,301 c: &ColorMask,302 frame: u64303) -> Option<CachedGlyph> {304 const placed = cache.place(305 &var device,306 TextureFormat::Rgba8Unorm,307 c.width,308 c.height,309 &c.pixels.view(),310 frame311 );312 if (placed is ::Some |p|) {313 return ::Some(CachedGlyph {314 .page = p.page,315 .plot = p.plot,316 .region = p.region,317 .left = c.left,318 .top = c.top,319 .color = true320 });321 }322 return ::None;323}324325// Where pixels went: their page and plot, and their region there.326type Placed = struct {327 page: u32,328 plot: u32,329 region: Rect,330};331332// A plot of a page.333type PlotAt = struct {334 page: u32,335 plot: u32,336};337338// Packs the pixels in a plot of the format, in a clear border of one339// pixel; None for no pixels, or more than a page holds.340fn place(341 self cache: &var GlyphCache,342 device: &var Device,343 format: TextureFormat,344 width: u32,345 height: u32,346 pixels: &[u8],347 frame: u64348) -> Option<Placed> {349 const side = cache.budget.page / ACROSS;350 if (351 width == 0352 || height == 0353 || width + 2 > cache.budget.page354 || height + 2 > cache.budget.page355 ) {356 return ::None;357 }358 const at = if (width + 2 > side || height + 2 > side) cache.large_page(359 &var device,360 format,361 width + 2,362 height + 2,363 frame364 ) else cache.plot_for(&var device, format, width + 2, height + 2, frame);365 var page = &var cache.pages.get_var(at.page to u64);366 const room = if (page.kind is ::Large) page.texture.width else side;367 const room_height = if (page.kind is ::Large) page.texture.height else side;368 var plot = &var page.plots.get_var(at.plot to u64);369 var area = if (370 plot.shelves.place(width + 2, height + 2, room, room_height) is ::Some |a|371 ) a else {372 panic "pkg::alloy::draw: a glyph's plot without room";373 };374 plot.used = frame;375 area.x += (at.plot % ACROSS) * side;376 area.y += (at.plot / ACROSS) * side;377 write_bordered(&var device, page.texture, &area, &pixels, false);378 return ::Some(Placed {379 .page = at.page,380 .plot = at.plot,381 .region = Rect::at(382 (area.x + 1) to f32,383 (area.y + 1) to f32,384 width to f32,385 height to f32386 )387 });388}389390// The plot an area of the size goes into: the most recently used of the391// budget's with room, an empty one, a new page's while the budget392// allows (large glyphs cleared for it), the least recently used the393// frame has not drawn from, cleared; past the budget only when the frame394// drew from every plot of it.395fn plot_for(396 self cache: &var GlyphCache,397 device: &var Device,398 format: TextureFormat,399 width: u32,400 height: u32,401 frame: u64402) -> PlotAt {403 if (cache.room(format, width, height, false) is ::Some |at|) {404 return at;405 }406 if (cache.make_room(format, PLOTS to u32, frame)) {407 const page = cache.new_page(408 &var device,409 format,410 PageKind::Plots,411 false,412 cache.budget.page,413 cache.budget.page414 );415 return PlotAt { .page = page, .plot = 0 };416 }417 if (cache.oldest(format, frame) is ::Some |at|) {418 cache.clear_plot(at);419 return at;420 }421 if (cache.room(format, width, height, true) is ::Some |at|) {422 return at;423 }424 const page = cache.new_page(425 &var device,426 format,427 PageKind::Plots,428 true,429 cache.budget.page,430 cache.budget.page431 );432 return PlotAt { .page = page, .plot = 0 };433}434435// The most recently used plot of the format with room, among the pages436// past the budget or within it, else an empty one.437fn room(438 self cache: &GlyphCache,439 format: TextureFormat,440 width: u32,441 height: u32,442 past: bool443) -> Option<PlotAt> {444 const side = cache.budget.page / ACROSS;445 var best: Option<PlotAt> = ::None;446 var best_used: u64 = 0;447 var empty: Option<PlotAt> = ::None;448 for (cache.pages.view(), [..cache.pages.length()]) |&page, k| {449 if (!(page.kind is ::Plots) || page.texture.format != format || page.past != past) {450 continue;451 }452 for ([..PLOTS]) |p| {453 const plot = &page.plots.get(p);454 const at = PlotAt { .page = k to u32, .plot = p to u32 };455 if (plot.shelves.is_empty()) {456 if (empty is ::None) {457 empty = ::Some(at);458 }459 } else if (460 (best is ::None || plot.used > best_used)461 && plot.shelves.fits(width, height, side, side)462 ) {463 best = ::Some(at);464 best_used = plot.used;465 }466 }467 }468 return if (best is ::Some) best else empty;469}470471// The plot of the budget's pages of the format used least recently,472// unless the frame drew from it.473fn oldest(self cache: &GlyphCache, format: TextureFormat, frame: u64) -> Option<PlotAt> {474 var found: Option<PlotAt> = ::None;475 var found_used: u64 = 0;476 for (cache.pages.view(), [..cache.pages.length()]) |&page, k| {477 if (!(page.kind is ::Plots) || page.texture.format != format || page.past) {478 continue;479 }480 for ([..PLOTS]) |p| {481 const used = page.plots.get(p).used;482 if (used < frame && (found is ::None || used < found_used)) {483 found = ::Some(PlotAt { .page = k to u32, .plot = p to u32 });484 found_used = used;485 }486 }487 }488 return found;489}490491// A texture of its own for a glyph larger than a plot, counted in the492// budget as the plots it covers, past it when no room is made.493fn large_page(494 self cache: &var GlyphCache,495 device: &var Device,496 format: TextureFormat,497 width: u32,498 height: u32,499 frame: u64500) -> PlotAt {501 const side = cache.budget.page / ACROSS;502 const weight = ((width + side - 1) / side) * ((height + side - 1) / side);503 const past = !cache.make_room(format, weight, frame);504 const page = cache.new_page(&var device, format, PageKind::Large, past, width, height);505 cache.pages.get_var(page to u64).weight = weight;506 return PlotAt { .page = page, .plot = 0 };507}508509// Whether the format's budget has room for the plots, large glyphs the510// frame has not drawn cleared, the least recently used first, to make511// it: released at the next frame's start.512fn make_room(self cache: &var GlyphCache, format: TextureFormat, weight: u32, frame: u64) -> bool {513 const budget = cache.budget_of(format);514 while (cache.weight_of(format) + weight > budget) {515 var found: Option<u64> = ::None;516 var found_used: u64 = 0;517 for (cache.pages.view(), [..cache.pages.length()]) |&page, k| {518 if (!(page.kind is ::Large)) {519 continue;520 }521 const plot = &page.plots.get(0);522 if (523 page.texture.format == format524 && !page.past525 && !plot.shelves.is_empty()526 && plot.used < frame527 && (found is ::None || plot.used < found_used)528 ) {529 found = ::Some(k);530 found_used = plot.used;531 }532 }533 const k = if (found is ::Some |f|) f else {534 return false;535 };536 cache.clear_plot(PlotAt { .page = k to u32, .plot = 0 });537 }538 return true;539}540541// A new page of the format, in a released page's slot if there is one.542fn new_page(543 self cache: &var GlyphCache,544 device: &var Device,545 format: TextureFormat,546 kind: PageKind,547 past: bool,548 width: u32,549 height: u32550) -> u32 {551 var slot = cache.pages.length();552 for ([..cache.pages.length()]) |k| {553 if (cache.pages.get(k).kind is ::Released) {554 slot = k;555 break;556 }557 }558 const texture = device.texture(&TextureDescriptor {559 .width = width,560 .height = height,561 .format = format,562 .usage = TEXTURE_SAMPLED | TEXTURE_COPY_DESTINATION563 });564 if (slot == cache.pages.length()) {565 cache.pages.push(GlyphPage {566 .texture = texture,567 .kind = PageKind::Released,568 .plots = Vector<Plot>::empty(),569 .past = past,570 .weight = 0571 });572 }573 var page = &var cache.pages.get_var(slot);574 page.texture = texture;575 page.kind = kind;576 page.past = past;577 page.weight = PLOTS to u32;578 for ([..if (kind is ::Large) 1 else PLOTS]) {579 page.plots.push(Plot::empty());580 }581 return slot to u32;582}583584// The plots the format's budget holds.585fn budget_of(self cache: &GlyphCache, format: TextureFormat) -> u32 {586 const pages = if (format is ::R8Unorm) cache.budget.coverage else cache.budget.color;587 return pages * PLOTS to u32;588}589590// The plots of the budget the format's pages take: those within it, a591// large glyph's while it holds one.592fn weight_of(self cache: &GlyphCache, format: TextureFormat) -> u32 {593 var total: u32 = 0;594 for (cache.pages.view()) |&page| {595 if (page.texture.format == format && !page.past && page.counts()) {596 total += page.weight;597 }598 }599 return total;600}601602fn counts(self page: &GlyphPage) -> bool => match (page.kind) {603 ::Plots true;604 ::Large !page.plots.get(0).shelves.is_empty();605 ::Released false;606};607608// Empties the plot, forgetting the glyphs it held.609fn clear_plot(self cache: &var GlyphCache, at: PlotAt) {610 const count = cache.pages.get(at.page to u64).plots.get(at.plot to u64).keys.length();611 for ([..count]) |k| {612 const key = cache.pages.get(at.page to u64).plots.get(at.plot to u64).keys.get(k);613 cache.forget(key, at);614 }615 var plot = &var cache.pages.get_var(at.page to u64).plots.get_var(at.plot to u64);616 plot.keys.clear();617 plot.shelves.clear();618 cache.cleared += 1;619}620621// Forgets the key's glyph, or tint, if it is still in the plot.622fn forget(self cache: &var GlyphCache, key: u64, at: PlotAt) {623 const inside = (c: &CachedGlyph) => c.page == at.page && c.plot == at.plot;624 if (625 cache.entries.try_get(&key) is ::Some |&entry|626 && entry is ::Placed |cached|627 && inside(&cached)628 ) {629 cache.entries.remove(&key);630 }631 if (cache.tinted.try_get_var(&key) is ::Some |&var tints|) {632 var k: u64 = 0;633 while (k < tints.length()) {634 if (tints.get(k).glyph is ::Some |cached| && inside(&cached)) {635 tints.swap_remove(k);636 } else {637 k += 1;638 }639 }640 if (tints.length() == 0) {641 cache.tinted.remove(&key);642 }643 }644}645646// At a frame's start, `last` the frame before: pages past the budget647// kept where the budget has room again, else their plots cleared once a648// frame does not draw from them, or while the budget's pages have plots649// the last frame did not use, which their glyphs then move into; pages650// past the budget and large glyphs' holding nothing released, their651// textures given back for their bind groups to go.652pub fn evict(self cache: &var GlyphCache, device: &var Device, last: u64) -> Vector<Texture> {653 cache.rasterized = 0;654 cache.cleared = 0;655 const formats: [TextureFormat : 2] = [TextureFormat::R8Unorm, TextureFormat::Rgba8Unorm];656 for (formats) |format| {657 for ([..cache.pages.length()]) |k| {658 const page = &cache.pages.get(k);659 if (660 page.past661 && page.texture.format == format662 && page.counts()663 && cache.weight_of(format) + page.weight <= cache.budget_of(format)664 ) {665 cache.pages.get_var(k).past = false;666 }667 }668 var spare = cache.spare(format, last);669 for ([..cache.pages.length()]) |k| {670 const page = &cache.pages.get(k);671 if (!page.past || page.texture.format != format) {672 continue;673 }674 for ([..page.plots.length()]) |p| {675 const plot = &cache.pages.get(k).plots.get(p);676 if (plot.shelves.is_empty()) {677 continue;678 }679 const unused = plot.used < last;680 if (unused || spare > 0 && cache.pages.get(k).kind is ::Plots) {681 if (!unused) {682 spare -= 1;683 }684 cache.clear_plot(PlotAt { .page = k to u32, .plot = p to u32 });685 }686 }687 }688 }689 var released = Vector<Texture>::empty();690 for (cache.pages.items()) |&var page| {691 const releases = match (page.kind) {692 ::Plots page.past && page.is_empty();693 ::Large page.plots.get(0).shelves.is_empty();694 ::Released false;695 };696 if (releases) {697 device.release(page.texture);698 released.push(page.texture);699 page.kind = PageKind::Released;700 page.plots = Vector<Plot>::empty();701 }702 }703 return move released;704}705706// How many plots of the budget's pages of the format are empty or were707// not used by the frame.708fn spare(self cache: &GlyphCache, format: TextureFormat, frame: u64) -> u32 {709 var count: u32 = 0;710 for (cache.pages.view()) |&page| {711 if (page.kind is ::Plots && page.texture.format == format && !page.past) {712 for (page.plots.view()) |&plot| {713 if (plot.shelves.is_empty() || plot.used < frame) {714 count += 1;715 }716 }717 }718 }719 return count;720}721722fn is_empty(self page: &GlyphPage) -> bool {723 for (page.plots.view()) |&plot| {724 if (!plot.shelves.is_empty()) {725 return false;726 }727 }728 return true;729}730731// Sets the budget: the pages of each format past it, the last made732// first, emptied and released from the next frame on. Pages of another733// size are released now, their textures given back for their bind734// groups to go.735pub fn set_budget(736 self cache: &var GlyphCache,737 device: &var Device,738 budget: GlyphBudget739) -> Vector<Texture> {740 var released = Vector<Texture>::empty();741 if (budget.page != cache.budget.page) {742 for (cache.pages.view()) |&page| {743 if (!(page.kind is ::Released)) {744 released.push(page.texture);745 }746 }747 cache.release(&var device);748 }749 cache.budget = budget;750 const formats: [TextureFormat : 2] = [TextureFormat::R8Unorm, TextureFormat::Rgba8Unorm];751 for (formats) |format| {752 const most = cache.budget_of(format);753 var taken: u32 = 0;754 for (cache.pages.items()) |&var page| {755 if (page.texture.format == format && page.counts()) {756 page.past = taken + page.weight > most;757 if (!page.past) {758 taken += page.weight;759 }760 }761 }762 }763 return move released;764}765766// What the cache holds, and what its last frame did.767pub fn stats(self cache: &GlyphCache) -> GlyphStats {768 var stats = GlyphStats {769 .pages = 0,770 .past = 0,771 .plots = 0,772 .bytes = 0,773 .entries = cache.entries.length(),774 .rasterized = cache.rasterized,775 .cleared = cache.cleared776 };777 for (cache.pages.view()) |&page| {778 if (page.kind is ::Released) {779 continue;780 }781 stats.pages += 1;782 if (page.past) {783 stats.past += 1;784 }785 for ([..page.plots.length()]) |p| {786 if (!page.plots.get(p).shelves.is_empty()) {787 stats.plots += 1;788 }789 }790 const t = &page.texture;791 stats.bytes += t.width to u64 * t.height to u64 * t.format.bytes_per_pixel();792 }793 return stats;794}795796pub fn release(self cache: &var GlyphCache, device: &var Device) {797 for (cache.pages.view()) |&page| {798 if (!(page.kind is ::Released)) {799 device.release(page.texture);800 }801 }802 cache.pages.clear();803 cache.entries = Map<u64, GlyphEntry>::empty();804 cache.tinted = Map<u64, Vector<Tint>>::empty();805 cache.marks = 0;806}