зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1874035 - Add custom Debug derives for bitflags with custom derives. r=gfx-reviewers,emilio,ErichDonGubler
bitflags 2 has a shortcoming with using custom derives: you can't use custom derives (for e.g. MallocSizeOf) at the same time as bitflags's for the derives it supports. See https://github.com/bitflags/bitflags/issues/395 Differential Revision: https://phabricator.services.mozilla.com/D199941
This commit is contained in:
Родитель
54cc50d168
Коммит
fb2aa57149
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
pub use bitflags::bitflags as bitflags2;
|
||||
pub use bitflags::parser;
|
||||
|
||||
// Copy of the macro from bitflags 1.3.2, with the implicit derives
|
||||
// removed, because in 2.0, they're expected to be explicitly given
|
||||
|
@ -30,9 +31,19 @@ macro_rules! bitflags {
|
|||
$($t:tt)*
|
||||
) => {
|
||||
$(#[$($outer)+])*
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
$vis struct $BitFlags($T);
|
||||
|
||||
impl core::fmt::Debug for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
core::write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
$crate::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags2! {
|
||||
impl $BitFlags: $T {
|
||||
$(
|
||||
|
|
|
@ -894,7 +894,7 @@ impl From<ClipItemKey> for ClipNode {
|
|||
// Flags that are attached to instances of clip nodes.
|
||||
#[cfg_attr(feature = "capture", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
pub struct ClipNodeFlags(u8);
|
||||
|
||||
bitflags! {
|
||||
|
@ -905,6 +905,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for ClipNodeFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When a clip node is found to be valid for a
|
||||
// clip chain instance, it's stored in an index
|
||||
// buffer style structure. This struct contains
|
||||
|
|
|
@ -612,7 +612,7 @@ pub struct MaskInstance {
|
|||
/// code should process this instance.
|
||||
#[cfg_attr(feature = "capture", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
pub struct BrushFlags(u16);
|
||||
|
||||
bitflags! {
|
||||
|
@ -646,6 +646,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for BrushFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience structure to encode into PrimitiveInstanceData.
|
||||
pub struct BrushInstance {
|
||||
pub prim_header_index: PrimitiveHeaderIndex,
|
||||
|
|
|
@ -70,7 +70,7 @@ const MAX_SEGMENTS: usize = 64;
|
|||
/// `write_transform_vertex()` function.
|
||||
#[cfg_attr(feature = "capture", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, MallocSizeOf)]
|
||||
pub struct EdgeAaSegmentMask(u8);
|
||||
|
||||
bitflags! {
|
||||
|
@ -86,6 +86,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for EdgeAaSegmentMask {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
|
||||
pub struct ItemFlags: u8 {
|
||||
|
|
|
@ -35,7 +35,7 @@ pub type ItemTag = (u64, u16);
|
|||
pub type ItemKey = u16;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
pub struct PrimitiveFlags(u8);
|
||||
|
||||
bitflags! {
|
||||
|
@ -59,6 +59,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for PrimitiveFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PrimitiveFlags {
|
||||
fn default() -> Self {
|
||||
PrimitiveFlags::IS_BACKFACE_VISIBLE
|
||||
|
@ -933,7 +943,7 @@ impl Hash for RasterSpace {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
pub struct StackingContextFlags(u8);
|
||||
|
||||
bitflags! {
|
||||
|
@ -948,6 +958,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for StackingContextFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for StackingContextFlags {
|
||||
fn default() -> Self {
|
||||
StackingContextFlags::empty()
|
||||
|
|
|
@ -182,7 +182,7 @@ impl Default for GlyphOptions {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, MallocSizeOf, Serialize, PeekPoke)]
|
||||
pub struct FontInstanceFlags(u32);
|
||||
|
||||
bitflags! {
|
||||
|
@ -220,6 +220,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for FontInstanceFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FontInstanceFlags {
|
||||
#[cfg(target_os = "windows")]
|
||||
fn default() -> FontInstanceFlags {
|
||||
|
|
|
@ -595,7 +595,7 @@ pub enum IntParameter {
|
|||
|
||||
/// Flags to track why we are rendering.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Default, Deserialize, MallocSizeOf, Serialize)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Default, Deserialize, MallocSizeOf, Serialize)]
|
||||
pub struct RenderReasons(u32);
|
||||
|
||||
bitflags! {
|
||||
|
@ -633,13 +633,23 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for RenderReasons {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderReasons {
|
||||
pub const NUM_BITS: u32 = 17;
|
||||
}
|
||||
|
||||
/// Flags to enable/disable various builtin debugging tools.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Default, Deserialize, MallocSizeOf, Serialize)]
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Default, Deserialize, MallocSizeOf, Serialize)]
|
||||
pub struct DebugFlags(u32);
|
||||
|
||||
bitflags! {
|
||||
|
@ -713,6 +723,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for DebugFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Information specific to a primitive type that
|
||||
/// uniquely identifies a primitive template by key.
|
||||
#[derive(Debug, Clone, Eq, MallocSizeOf, PartialEq, Hash, Serialize, Deserialize)]
|
||||
|
|
|
@ -167,7 +167,7 @@ fn split_from_end<T>(s: &[T], at: usize) -> (&[T], &[T]) {
|
|||
}
|
||||
|
||||
/// Flags that indicate at which point of parsing a selector are we.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ToShmem)]
|
||||
#[derive(Clone, Copy, Default, Eq, PartialEq, ToShmem)]
|
||||
pub(crate) struct SelectorFlags(u8);
|
||||
|
||||
bitflags! {
|
||||
|
@ -181,6 +181,16 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for SelectorFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if self.is_empty() {
|
||||
write!(f, "{:#x}", Self::empty().bits())
|
||||
} else {
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SelectorFlags {
|
||||
/// When you nest a pseudo-element with something like:
|
||||
///
|
||||
|
|
Загрузка…
Ссылка в новой задаче