Skip to content

Instantly share code, notes, and snippets.

@djg
Created December 16, 2018 23:36
Show Gist options
  • Save djg/6e82b5cb716ebacc1058be007b6df35d to your computer and use it in GitHub Desktop.
Save djg/6e82b5cb716ebacc1058be007b6df35d to your computer and use it in GitHub Desktop.
WebRender ImageKey and ImageTemplate
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ImageKey {
pub common: PrimKeyCommonData,
pub key: ApiImageKey,
pub stretch_size: SizeKey,
pub tile_spacing: SizeKey,
pub color: ColorU,
pub sub_rect: Option<DeviceIntRect>,
pub image_rendering: ImageRendering,
pub alpha_type: AlphaType,
}
pub struct Image {
pub key: ApiImageKey,
pub stretch_size: SizeKey,
pub tile_spacing: SizeKey,
pub color: ColorU,
pub sub_rect: Option<DeviceIntRect>,
pub image_rendering: ImageRendering,
pub alpha_type: AlphaType,
}
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct ImageTemplate {
pub common: PrimTemplateCommonData,
pub key: ApiImageKey,
pub stretch_size: LayoutSize,
pub tile_spacing: LayoutSize,
pub color: ColorF,
pub source: ImageSource,
pub image_rendering: ImageRendering,
pub sub_rect: Option<DeviceIntRect>,
pub alpha_type: AlphaType,
}
/// Fields of ImageKey and Image are in common. Proposed refactor into
pub struct Image {
pub key: ApiImageKey,
pub stretch_size: SizeKey,
pub tile_spacing: SizeKey,
pub color: ColorU,
pub sub_rect: Option<DeviceIntRect>,
pub image_rendering: ImageRendering,
pub alpha_type: AlphaType,
}
pub struct PrimKey<T> {
pub kind: T,
// These are the fields of PrimKeyCommonData. We may want to keep
// common data to allow split borrowing? (ie. We can present a common
// interface to return the common data for a prim key)
pub is_backface_visible: bool,
pub prim_size: SizeKey,
pub prim_relative_clip_rect: RectangleKey,
}
/// Split Template similarly to allow split borrow between template data
/// and GPU Handle, for example.
pub ImageTemplateKind {
pub color_depth: ColorDepth,
pub yuv_key: [ApiImageKey; 3],
pub format: YuvFormat,
pub color_space: YuvColorSpace,
pub image_rendering: ImageRendering,
}
pub struct PrimTemplate<T>
pub kind: T,
pub is_backface_visible: bool,
pub prim_size: LayoutSize,
pub prim_relative_clip_rect: LayoutRect,
pub opacity: PrimitiveOpacity,
/// The GPU cache handle for a primitive template. Since this structure
/// is retained across display lists by interning, this GPU cache handle
/// also remains valid, which reduces the number of updates to the GPU
/// cache when a new display list is processed.
pub gpu_cache_handle: GpuCacheHandle,
}
pub type ImageTemplate = PrimTemplate<ImageTemplateKind>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment