picture.rs (3169B)
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 api::RasterSpace; 6 use crate::scene_building::IsVisible; 7 use crate::intern::{Internable, InternDebug, Handle as InternHandle}; 8 use crate::internal_types::LayoutPrimitiveInfo; 9 use crate::picture_composite_mode::PictureCompositeKey; 10 use crate::prim_store::{ 11 PrimitiveInstanceKind, PrimitiveStore, 12 InternablePrimitive, 13 }; 14 15 #[cfg_attr(feature = "capture", derive(Serialize))] 16 #[cfg_attr(feature = "replay", derive(Deserialize))] 17 #[derive(Debug, Clone, Eq, MallocSizeOf, PartialEq, Hash)] 18 pub struct Picture { 19 pub composite_mode_key: PictureCompositeKey, 20 pub raster_space: RasterSpace, 21 } 22 23 #[cfg_attr(feature = "capture", derive(Serialize))] 24 #[cfg_attr(feature = "replay", derive(Deserialize))] 25 #[derive(Debug, Clone, Eq, MallocSizeOf, PartialEq, Hash)] 26 pub struct PictureKey { 27 pub composite_mode_key: PictureCompositeKey, 28 pub raster_space: RasterSpace, 29 } 30 31 impl PictureKey { 32 pub fn new( 33 pic: Picture, 34 ) -> Self { 35 PictureKey { 36 composite_mode_key: pic.composite_mode_key, 37 raster_space: pic.raster_space, 38 } 39 } 40 } 41 42 impl InternDebug for PictureKey {} 43 44 #[cfg_attr(feature = "capture", derive(Serialize))] 45 #[cfg_attr(feature = "replay", derive(Deserialize))] 46 #[derive(MallocSizeOf)] 47 pub struct PictureTemplate; 48 49 impl From<PictureKey> for PictureTemplate { 50 fn from(_: PictureKey) -> Self { 51 PictureTemplate 52 } 53 } 54 55 pub type PictureDataHandle = InternHandle<Picture>; 56 57 impl Internable for Picture { 58 type Key = PictureKey; 59 type StoreData = PictureTemplate; 60 type InternData = (); 61 const PROFILE_COUNTER: usize = crate::profiler::INTERNED_PICTURES; 62 } 63 64 impl InternablePrimitive for Picture { 65 fn into_key( 66 self, 67 _: &LayoutPrimitiveInfo, 68 ) -> PictureKey { 69 PictureKey::new(self) 70 } 71 72 fn make_instance_kind( 73 _key: PictureKey, 74 _: PictureDataHandle, 75 _: &mut PrimitiveStore, 76 ) -> PrimitiveInstanceKind { 77 // Should never be hit as this method should not be 78 // called for pictures. 79 unreachable!(); 80 } 81 } 82 83 impl IsVisible for Picture { 84 fn is_visible(&self) -> bool { 85 true 86 } 87 } 88 89 #[test] 90 #[cfg(target_pointer_width = "64")] 91 fn test_struct_sizes() { 92 use std::mem; 93 // The sizes of these structures are critical for performance on a number of 94 // talos stress tests. If you get a failure here on CI, there's two possibilities: 95 // (a) You made a structure smaller than it currently is. Great work! Update the 96 // test expectations and move on. 97 // (b) You made a structure larger. This is not necessarily a problem, but should only 98 // be done with care, and after checking if talos performance regresses badly. 99 assert_eq!(mem::size_of::<Picture>(), 96, "Picture size changed"); 100 assert_eq!(mem::size_of::<PictureTemplate>(), 0, "PictureTemplate size changed"); 101 assert_eq!(mem::size_of::<PictureKey>(), 96, "PictureKey size changed"); 102 }