encodeStripPlan function
Serializes plan into one compact buffer (see the layout above).
Implementation
Uint8List encodeStripPlan(StripPlan plan) {
final w = _PlanWriter();
w.u8(_planFormatVersion);
w.u32(plan.totalFlushPoints);
w.u32(plan.deviceWidth);
w.u32(plan.deviceHeight);
final m = plan.pageToDevice;
w.f64(m.a);
w.f64(m.b);
w.f64(m.c);
w.f64(m.d);
w.f64(m.e);
w.f64(m.f);
w.f64(plan.tolerance);
w.u8(plan.slugGlyphs ? 1 : 0);
w.u32(plan.slugQuadCount);
w.u32(plan.slugFallbackOutlineRuns);
w.u32(plan.slugFallbackOrdinals.length);
for (final ordinal in plan.slugFallbackOrdinals) {
w.u32(ordinal);
}
w.u32(plan.batches.length);
for (final batch in plan.batches) {
w.u32(batch.flushOrdinal);
w.u32(batch.stripCount);
w.u32(batch.atlasWidth);
w.u32(batch.atlasHeight);
w.raw(batch.atlasPixels);
w.u32(batch.chunks.length);
for (final chunk in batch.chunks) {
final quads = chunk.positions.length ~/ 8;
w.u32(quads);
w.u32(chunk.alphaBase);
w.rawView(chunk.positions.buffer, chunk.positions.offsetInBytes,
chunk.positions.lengthInBytes);
w.rawView(
chunk.textureCoordinates.buffer,
chunk.textureCoordinates.offsetInBytes,
chunk.textureCoordinates.lengthInBytes);
w.rawView(chunk.colors.buffer, chunk.colors.offsetInBytes,
chunk.colors.lengthInBytes);
w.rawView(chunk.indices.buffer, chunk.indices.offsetInBytes,
chunk.indices.lengthInBytes);
}
}
w.u32(plan.slugBatches.length);
for (final batch in plan.slugBatches) {
w.u32(batch.flushOrdinal);
w.u32(batch.quadCount);
w.u32(batch.atlasWidth);
w.u32(batch.atlasHeight);
w.f64(batch.cellHeight);
w.raw(batch.atlasPixels);
w.u32(batch.chunks.length);
for (final chunk in batch.chunks) {
final quads = chunk.positions.length ~/ 8;
w.u32(quads);
w.rawView(chunk.positions.buffer, chunk.positions.offsetInBytes,
chunk.positions.lengthInBytes);
w.rawView(
chunk.textureCoordinates.buffer,
chunk.textureCoordinates.offsetInBytes,
chunk.textureCoordinates.lengthInBytes);
w.rawView(chunk.colors.buffer, chunk.colors.offsetInBytes,
chunk.colors.lengthInBytes);
w.rawView(chunk.indices.buffer, chunk.indices.offsetInBytes,
chunk.indices.lengthInBytes);
}
}
return w.takeBytes();
}