backdrop.rs (4756B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 use crate::intern::{Internable, InternDebug, Handle as InternHandle}; 6 use crate::internal_types::LayoutPrimitiveInfo; 7 use crate::prim_store::{ 8 InternablePrimitive, PrimitiveInstanceKind, PrimKey, PrimTemplate, 9 PrimTemplateCommonData, PrimitiveStore, PictureIndex, 10 }; 11 use crate::scene_building::IsVisible; 12 13 #[cfg_attr(feature = "capture", derive(Serialize))] 14 #[cfg_attr(feature = "replay", derive(Deserialize))] 15 #[derive(Debug, Clone, Eq, PartialEq, MallocSizeOf, Hash)] 16 pub struct BackdropCapture { 17 } 18 19 #[cfg_attr(feature = "capture", derive(Serialize))] 20 #[cfg_attr(feature = "replay", derive(Deserialize))] 21 #[derive(Debug, Clone, Eq, PartialEq, MallocSizeOf, Hash)] 22 pub struct BackdropRender { 23 } 24 25 impl From<BackdropCapture> for BackdropCaptureData { 26 fn from(_backdrop: BackdropCapture) -> Self { 27 BackdropCaptureData { 28 } 29 } 30 } 31 32 impl From<BackdropRender> for BackdropRenderData { 33 fn from(_backdrop: BackdropRender) -> Self { 34 BackdropRenderData { 35 } 36 } 37 } 38 39 pub type BackdropCaptureKey = PrimKey<BackdropCapture>; 40 pub type BackdropRenderKey = PrimKey<BackdropRender>; 41 42 impl BackdropCaptureKey { 43 pub fn new( 44 info: &LayoutPrimitiveInfo, 45 backdrop_capture: BackdropCapture, 46 ) -> Self { 47 BackdropCaptureKey { 48 common: info.into(), 49 kind: backdrop_capture, 50 } 51 } 52 } 53 54 impl BackdropRenderKey { 55 pub fn new( 56 info: &LayoutPrimitiveInfo, 57 backdrop_render: BackdropRender, 58 ) -> Self { 59 BackdropRenderKey { 60 common: info.into(), 61 kind: backdrop_render, 62 } 63 } 64 } 65 66 impl InternDebug for BackdropCaptureKey {} 67 impl InternDebug for BackdropRenderKey {} 68 69 #[cfg_attr(feature = "capture", derive(Serialize))] 70 #[cfg_attr(feature = "replay", derive(Deserialize))] 71 #[derive(Debug, MallocSizeOf)] 72 pub struct BackdropCaptureData { 73 } 74 75 #[cfg_attr(feature = "capture", derive(Serialize))] 76 #[cfg_attr(feature = "replay", derive(Deserialize))] 77 #[derive(Debug, MallocSizeOf)] 78 pub struct BackdropRenderData { 79 } 80 81 pub type BackdropCaptureTemplate = PrimTemplate<BackdropCaptureData>; 82 pub type BackdropRenderTemplate = PrimTemplate<BackdropRenderData>; 83 84 impl From<BackdropCaptureKey> for BackdropCaptureTemplate { 85 fn from(backdrop: BackdropCaptureKey) -> Self { 86 let common = PrimTemplateCommonData::with_key_common(backdrop.common); 87 88 BackdropCaptureTemplate { 89 common, 90 kind: backdrop.kind.into(), 91 } 92 } 93 } 94 95 impl From<BackdropRenderKey> for BackdropRenderTemplate { 96 fn from(backdrop: BackdropRenderKey) -> Self { 97 let common = PrimTemplateCommonData::with_key_common(backdrop.common); 98 99 BackdropRenderTemplate { 100 common, 101 kind: backdrop.kind.into(), 102 } 103 } 104 } 105 106 pub type BackdropCaptureDataHandle = InternHandle<BackdropCapture>; 107 pub type BackdropRenderDataHandle = InternHandle<BackdropRender>; 108 109 impl Internable for BackdropCapture { 110 type Key = BackdropCaptureKey; 111 type StoreData = BackdropCaptureTemplate; 112 type InternData = (); 113 const PROFILE_COUNTER: usize = crate::profiler::INTERNED_BACKDROP_CAPTURES; 114 } 115 116 impl Internable for BackdropRender { 117 type Key = BackdropRenderKey; 118 type StoreData = BackdropRenderTemplate; 119 type InternData = (); 120 const PROFILE_COUNTER: usize = crate::profiler::INTERNED_BACKDROP_RENDERS; 121 } 122 123 impl InternablePrimitive for BackdropCapture { 124 fn into_key( 125 self, 126 info: &LayoutPrimitiveInfo, 127 ) -> BackdropCaptureKey { 128 BackdropCaptureKey::new(info, self) 129 } 130 131 fn make_instance_kind( 132 _key: BackdropCaptureKey, 133 data_handle: BackdropCaptureDataHandle, 134 _prim_store: &mut PrimitiveStore, 135 ) -> PrimitiveInstanceKind { 136 PrimitiveInstanceKind::BackdropCapture { 137 data_handle, 138 } 139 } 140 } 141 142 impl InternablePrimitive for BackdropRender { 143 fn into_key( 144 self, 145 info: &LayoutPrimitiveInfo, 146 ) -> BackdropRenderKey { 147 BackdropRenderKey::new(info, self) 148 } 149 150 fn make_instance_kind( 151 _key: BackdropRenderKey, 152 data_handle: BackdropRenderDataHandle, 153 _prim_store: &mut PrimitiveStore, 154 ) -> PrimitiveInstanceKind { 155 PrimitiveInstanceKind::BackdropRender { 156 data_handle, 157 pic_index: PictureIndex::INVALID, 158 } 159 } 160 } 161 162 impl IsVisible for BackdropCapture { 163 fn is_visible(&self) -> bool { 164 true 165 } 166 } 167 168 impl IsVisible for BackdropRender { 169 fn is_visible(&self) -> bool { 170 true 171 } 172 }