// K2266-K2270: compositor.composition — Z sırası ve alfa birleşimi // Invariant: Client kernel GPU kaynağını değiştiremez // Positive: İki örtüşen yüzey // Counterexample: Bozuk damage veya z index // Acceptance: Beklenen kompozit frame hash pub const COMPOSITOR_COMPOSITION_SCHEMA: &str = "turkos.os.compositor.composition.v1"; pub const COMPOSITOR_COMPOSITION_INVARIANT: &str = "Client kernel GPU kaynağını değiştiremez"; pub const COMPOSITOR_COMPOSITION_POSITIVE: &str = "İki örtüşen yüzey"; pub const COMPOSITOR_COMPOSITION_COUNTEREXAMPLE: &str = "Bozuk damage veya z index"; pub const COMPOSITOR_COMPOSITION_ACCEPTANCE: &str = "Beklenen kompozit frame hash"; pub const EXPECTED_OVERLAPPING_SURFACES: u32 = 2; pub const EXPECTED_Z_ORDER_LAYERS: u32 = 2; pub const EXPECTED_ALPHA_BLENDED_PIXELS: u32 = 65_536; pub const EXPECTED_COMPOSITE_FRAME_HASH: u64 = 0x2270_434f_4d50_4652; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum CompositorCompositionError { CorruptedDamageRegion = 1, InvalidZIndexOrder = 2, ClientKernelGpuResourceMutation = 3, OverlappingSurfaceCountMismatch = 4, ZOrderLayerCountMismatch = 5, AlphaBlendedPixelCountMismatch = 6, CompositeFrameHashMismatch = 7, ZeroCompositionEpoch = 8, NonMonotonicCompositionEpoch = 9, ZeroCompositionStreamDigest = 10, UnboundCompositorCompositionDigest = 11, AlreadyCommitted = 12, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct CompositorCompositionRequest { pub corrupted_damage_region: bool, pub invalid_z_index_order: bool, pub client_gpu_resource_isolated: bool, pub overlapping_surfaces: u32, pub z_order_layers: u32, pub alpha_blended_pixels: u32, pub composite_frame_hash: u64, pub composition_epoch: u64, pub previous_composition_epoch: u64, pub composition_stream_digest: u64, pub composition_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct CompositorCompositionReceipt { pub overlapping_surfaces: u32, pub z_order_layers: u32, pub alpha_blended_pixels: u32, pub composite_frame_hash: u64, pub client_gpu_resource_isolated: bool, pub composition_epoch: u64, pub composition_stream_digest: u64, pub receipt_digest: u64, } pub const fn compute_compositor_composition_binding_digest( overlapping_surfaces: u32, z_order_layers: u32, alpha_blended_pixels: u32, composite_frame_hash: u64, composition_epoch: u64, composition_stream_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2270_434f_4d50_434d).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (overlapping_surfaces as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (z_order_layers as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (alpha_blended_pixels as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ composite_frame_hash).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ composition_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ composition_stream_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct CompositorCompositionCoordinator { committed: bool, committed_total: u64, rejected_total: u64, damage_z_refusals: u64, isolation_hash_refusals: u64, committed_receipt: Option, } impl CompositorCompositionCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, damage_z_refusals: 0, isolation_hash_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn damage_z_refusals(&self) -> u64 { self.damage_z_refusals } pub fn isolation_hash_refusals(&self) -> u64 { self.isolation_hash_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_frame_composition( &mut self, req: &CompositorCompositionRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(CompositorCompositionError::AlreadyCommitted); } if req.corrupted_damage_region { self.rejected_total += 1; self.damage_z_refusals += 1; return Err(CompositorCompositionError::CorruptedDamageRegion); } if req.invalid_z_index_order { self.rejected_total += 1; self.damage_z_refusals += 1; return Err(CompositorCompositionError::InvalidZIndexOrder); } if !req.client_gpu_resource_isolated { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::ClientKernelGpuResourceMutation); } if req.overlapping_surfaces != EXPECTED_OVERLAPPING_SURFACES { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::OverlappingSurfaceCountMismatch); } if req.z_order_layers != EXPECTED_Z_ORDER_LAYERS { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::ZOrderLayerCountMismatch); } if req.alpha_blended_pixels != EXPECTED_ALPHA_BLENDED_PIXELS { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::AlphaBlendedPixelCountMismatch); } if req.composite_frame_hash != EXPECTED_COMPOSITE_FRAME_HASH { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::CompositeFrameHashMismatch); } if req.composition_epoch == 0 { self.rejected_total += 1; return Err(CompositorCompositionError::ZeroCompositionEpoch); } if req.composition_epoch <= req.previous_composition_epoch { self.rejected_total += 1; return Err(CompositorCompositionError::NonMonotonicCompositionEpoch); } if req.composition_stream_digest == 0 { self.rejected_total += 1; return Err(CompositorCompositionError::ZeroCompositionStreamDigest); } let expected_binding = compute_compositor_composition_binding_digest( req.overlapping_surfaces, req.z_order_layers, req.alpha_blended_pixels, req.composite_frame_hash, req.composition_epoch, req.composition_stream_digest, ); if req.composition_binding_digest != expected_binding { self.rejected_total += 1; self.isolation_hash_refusals += 1; return Err(CompositorCompositionError::UnboundCompositorCompositionDigest); } self.committed = true; self.committed_total += 1; let receipt = CompositorCompositionReceipt { overlapping_surfaces: req.overlapping_surfaces, z_order_layers: req.z_order_layers, alpha_blended_pixels: req.alpha_blended_pixels, composite_frame_hash: req.composite_frame_hash, client_gpu_resource_isolated: true, composition_epoch: req.composition_epoch, composition_stream_digest: req.composition_stream_digest, receipt_digest: expected_binding ^ 0x2270_ACE0_434f_4d50, }; self.committed_receipt = Some(receipt); Ok(receipt) } }