fonts: Add MallocSizeOf implementation for FontContext (#32206)

* fonts: Add `MallocSizeOf` implementation for `FontContext`

Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

* android: remove unused imports in font_list.rs

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Martin Robinson 2024-05-03 11:54:29 +02:00 committed by GitHub
parent 160c7c0b0f
commit 1c9120c293
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 119 additions and 25 deletions

View file

@ -7,6 +7,7 @@ use std::ops::RangeInclusive;
use std::sync::Arc;
use atomic_refcell::AtomicRefCell;
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use style::computed_values::font_stretch::T as FontStretch;
@ -27,11 +28,12 @@ pub type FontTemplateRef = Arc<AtomicRefCell<FontTemplate>>;
/// to be expanded or refactored when we support more of the font styling parameters.
///
/// NB: If you change this, you will need to update `style::properties::compute_font_hash()`.
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, Hash, MallocSizeOf, PartialEq, Serialize)]
pub struct FontTemplateDescriptor {
pub weight: (FontWeight, FontWeight),
pub stretch: (FontStretch, FontStretch),
pub style: (FontStyle, FontStyle),
#[ignore_malloc_size_of = "MallocSizeOf does not yet support RangeInclusive"]
pub unicode_range: Option<Vec<RangeInclusive<u32>>>,
}
@ -134,6 +136,14 @@ pub struct FontTemplate {
pub data: Option<Arc<Vec<u8>>>,
}
impl malloc_size_of::MallocSizeOf for FontTemplate {
fn size_of(&self, ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
self.identifier.size_of(ops) +
self.descriptor.size_of(ops) +
self.data.as_ref().map_or(0, |data| (*data).size_of(ops))
}
}
impl Debug for FontTemplate {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
self.identifier.fmt(f)