testing library

A graphics backend that draws nothing and remembers everything.

The counterpart to the fake texture source in frame_resources_test.dart, and it exists for the same reason. Every type a pass used to name — gpu.RenderPass, gpu.HostBuffer, gpu.Shader, gpu.RenderPipeline — needed a live device to construct, so nothing that encoded anything could be tested at all. What a node draws was checked by looking at a golden image twelve minutes later, or not at all.

With the backend arriving as a value, a node can be handed one of these and asked what it did: which passes it opened, what they were attached to, what state it left them in, what it bound and how many times it drew.

Why it is in lib/, and in this package

It was four hundred and seventy-five lines in two copies, and they had already drifted. flutter3d/test/fake_backend.dart and flutter3d_particles/test/fake_backend.dart were the same file down to the paragraph above — which still names a test that only exists in one of them — and the particles copy was twenty-six lines behind: no pendingFrames, no completesImmediately, no uploadedPixels. A test written against it could not ask the question those exist to answer, and nothing said so.

This package rather than a new one, because that is what it depends on: flutter3d_hardware and flutter/widgets, and nothing else. A separate flutter3d_fakes would be a twenty-second workspace entry holding one file.

In lib/ rather than in a shared test/, because a package cannot import another package's test/ — which is the reason there were two copies.

import 'package:flutter3d_hardware/testing.dart';

Recorded and its subclasses — one entry per thing a pass was told to do — are src/testing_recorded.dart. FakePass, the CommandEncoder that records them, is src/testing_fake_pass.dart. FakeShaderLibrary and FakeBackend, the GraphicsDevice that opens one, are src/testing_fake_backend.dart. All three are re-exported from here.

So is SynchronousBufferReadback, since 1.0: the read that stalls the caller until the GPU is done is a test's or a tool's, never a frame's, so the main library does not offer it. A backend that has it imports it from here to mix it in.

And MaskedDevice, since 1.0.0-rc.1: any live device, answering as if it lacked the features a test names, so the fallback branch of each runs on the machine at hand.

Classes

FakeBackend
A device that records rather than draws.
FakeComputePass
A compute pass that records rather than runs: each call a RecordedCall in commands, in order, after the checks a real encoder makes (the storage range and its alignment, the dispatch size).
FakeCubeTarget
One cube render target a FakeBackend was asked for, as FakeBackend.createdCubeRenderTargets lists it.
FakeGeometryOverwrite
One overwrite of a geometry buffer a FakeBackend recorded, as FakeBackend.overwrites lists it: wiring, not content.
FakeLoadedShaderLibrary
What FakeBackend.loadShaders hands back: the bundle's own names, answered with handles that survive a reload.
FakeMapping
A mapping of bytes a fake never had: zeros, handed back on unmap.
FakePass
A pass that was opened, and everything that went into it.
FakeReadback
One readback a FakeBackend was asked for, as FakeBackend.readbacks lists it.
FakeShaderLibrary
A bundle that has every stage anybody asks for, except the ones it is told to withhold.
FakeTextureOverwrite
One overwrite of a texture a FakeBackend recorded, as FakeBackend.overwrittenTextures lists it: wiring, not content.
FakeTransfer
A transfer pass that records its copies into the device's calls, and refuses those the device's features lack.
MaskedDevice
inner, answering as if it lacked MaskedDevice.disabledFeatures.
Recorded
One thing recorded into a pass, in order.
RecordedAlphaToCoverage
PassEncoder.setAlphaToCoverage, in sequence; see RecordedPrimitiveType.
RecordedBlend
PassEncoder.setBlend, for one colour attachment.
RecordedBlendColor
PassEncoder.setBlendColor.
RecordedCall
A 1.0-surface call — a storage bind, a query, an indirect or bundled draw, a buffer write, a copy — recorded by name with its arguments.
RecordedClearBindings
PassEncoder.clearBindings.
RecordedCullMode
PassEncoder.setCullMode, in sequence; see RecordedPrimitiveType.
RecordedDepthCompare
PassEncoder.setDepthCompare, in sequence; see RecordedPrimitiveType.
RecordedDepthWrite
PassEncoder.setDepthWrite, in sequence; see RecordedPrimitiveType.
RecordedDraw
PassEncoder.draw, with the instance count and index window it asked for.
RecordedIndices
PassEncoder.bindIndexBuffer or bindIndexData: the width and count, not which buffer.
RecordedPipeline
PassEncoder.bindPipeline.
RecordedPolygonMode
PassEncoder.setPolygonMode, in sequence; see RecordedPrimitiveType.
RecordedPrimitiveType
Rasteriser state, recorded in sequence as well as kept as a field.
RecordedScissor
PassEncoder.setScissor.
RecordedStencil
A stencil configuration, with the back face only when one was named.
RecordedStencilReference
PassEncoder.setStencilReference, in sequence; see RecordedPrimitiveType.
RecordedTexture
PassEncoder.bindTexture.
RecordedUniformBlock
PassEncoder.bindUniformBlock.
RecordedVertices
PassEncoder.bindVertexBuffer or bindVertexData: how many vertices, not which buffer.
RecordedViewport
PassEncoder.setViewport.
RecordedWindingOrder
PassEncoder.setWindingOrder, in sequence; see RecordedPrimitiveType.

Mixins

SynchronousBufferReadback
A device that reads a buffer back in the calling turn — DeviceFeature.synchronousReadback.

Functions

computePlacementOf(ComputeSite site) → ComputePlacement
Where site is, for a test checking the rule — exported from package:flutter3d_hardware/testing.dart only.