Skip to main content

PlatformAtlas

Trait PlatformAtlas 

Source
pub trait PlatformAtlas {
    // Required methods
    fn get_or_insert_with<'a>(
        &self,
        key: AtlasKey,
        build: &mut dyn FnMut() -> Result<Option<(Size<DevicePixels>, Cow<'a, [u8]>)>>,
    ) -> Result<Option<AtlasTile>>;
    fn remove(&self, key: &AtlasKey);

    // Provided methods
    fn upload_from_gpu(
        &self,
        _key: &AtlasKey,
        _size: Size<DevicePixels>,
        _texture: GpuTextureHandle,
    ) -> Result<Option<AtlasTile>> { ... }
    fn upload_from_d3d12(
        &self,
        _key: &AtlasKey,
        _size: Size<DevicePixels>,
        _texture: D3D12TextureHandle,
        _owner: Arc<dyn Any + Send + Sync>,
    ) -> Result<Option<AtlasTile>> { ... }
    fn upload_from_metal(
        &self,
        _key: &AtlasKey,
        _size: Size<DevicePixels>,
        _texture: GpuTextureHandle,
        _ready: Option<(*mut c_void, u64)>,
        _owner: Arc<dyn Any + Send + Sync>,
    ) -> Result<Option<AtlasTile>> { ... }
    fn tile(&self, _key: &AtlasKey) -> Option<AtlasTile> { ... }
    fn write_bytes(
        &self,
        _key: &AtlasKey,
        _size: Size<DevicePixels>,
        _bytes: &[u8],
    ) -> Result<Option<AtlasTile>> { ... }
    fn write_hdr_bytes(
        &self,
        _key: &AtlasKey,
        _size: Size<DevicePixels>,
        _bytes: &[u8],
    ) -> Result<Option<AtlasTile>> { ... }
    fn stats(&self) -> Option<AtlasStats> { ... }
}

Required Methods§

Source

fn get_or_insert_with<'a>( &self, key: AtlasKey, build: &mut dyn FnMut() -> Result<Option<(Size<DevicePixels>, Cow<'a, [u8]>)>>, ) -> Result<Option<AtlasTile>>

The builder runs with the atlas locked and must not re-enter the same atlas.

Source

fn remove(&self, key: &AtlasKey)

Provided Methods§

Source

fn upload_from_gpu( &self, _key: &AtlasKey, _size: Size<DevicePixels>, _texture: GpuTextureHandle, ) -> Result<Option<AtlasTile>>

Fill the tile for key from a texture that is ALREADY in the renderer’s own GPU memory, with no CPU round trip — the tile is allocated on the first call and overwritten in place on every call after it.

This is the escape hatch for producers that decode straight onto the renderer’s device (a hardware video decoder, a compute pass). The ordinary PlatformAtlas::get_or_insert_with path can only accept Cow<[u8]>, which for such a producer means GPU → system memory → GPU for pixels that never needed to leave VRAM.

Unlike get_or_insert_with this is not memoised on the key: a caller that keeps ONE key per element and calls this once per frame gets one stable tile updated in place, which is the point — a fresh key per frame would allocate and free an atlas tile every frame.

Returns Ok(None) when the backend has no GPU path, when the handle is null, or when the texture is not one this atlas can copy from (wrong device, wrong format, too small). None is not an error: the caller is expected to have a CPU fallback, and the reason is logged once.

§Contract

texture is BORROWED for the duration of the call. On Windows it must be an ID3D11Texture2D created on the device that gpui_windows::renderer_d3d11_device() publishes, in DXGI_FORMAT_B8G8R8A8_UNORM, at least size in each dimension.

Source

fn upload_from_d3d12( &self, _key: &AtlasKey, _size: Size<DevicePixels>, _texture: D3D12TextureHandle, _owner: Arc<dyn Any + Send + Sync>, ) -> Result<Option<AtlasTile>>

Copies a straight-alpha BGRA8 D3D12 texture on this atlas’s device. The source is in RENDER_TARGET state before and after the copy. Its producer signals ready_fence at ready_value; the consumer waits on its GPU queue. owner retains the producer allocation and fence until the copy completes, not merely until this function returns.

Source

fn upload_from_metal( &self, _key: &AtlasKey, _size: Size<DevicePixels>, _texture: GpuTextureHandle, _ready: Option<(*mut c_void, u64)>, _owner: Arc<dyn Any + Send + Sync>, ) -> Result<Option<AtlasTile>>

vue-native fork: copies a straight-alpha BGRA8Unorm (or _sRGB) id<MTLTexture> on this atlas’s device into the tile for key, on the renderer’s queue. With ready (an id<MTLSharedEvent> and a value) the copy waits on the GPU until the event reaches it; without, the texture must already be written. owner is retained until the copy completes.

Source

fn tile(&self, _key: &AtlasKey) -> Option<AtlasTile>

vue-native fork: the tile key maps to now, if any. None from a backend that does not say, which makes every crate::Window::write_image_tile report a moved tile: correct, only never the cheap path.

Source

fn write_bytes( &self, _key: &AtlasKey, _size: Size<DevicePixels>, _bytes: &[u8], ) -> Result<Option<AtlasTile>>

vue-native fork: writes bytes (size, in the key’s texture format, rows packed) into the tile for key, overwriting it in place when it exists at this size and taking a new one otherwise. The CPU twin of PlatformAtlas::upload_from_gpu: not memoised, one tile per key.

Ok(None) when the backend has no such path; the caller then removes the key and inserts it again, which always works but moves the tile.

Source

fn write_hdr_bytes( &self, _key: &AtlasKey, _size: Size<DevicePixels>, _bytes: &[u8], ) -> Result<Option<AtlasTile>>

vue-native fork: PlatformAtlas::write_bytes into an AtlasTextureKind::PolychromeHdr tile: bytes are RGBA half floats, 8 a pixel. Ok(None) from a backend without HDR tiles.

Source

fn stats(&self) -> Option<AtlasStats>

vue-native fork: the atlas’s footprint, per texture kind — for an embedder’s memory report. None from a backend that does not keep count.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§