diff --git a/gfx/2d/FontFeature.h b/gfx/2d/FontFeature.h new file mode 100644 index 000000000000..456e018a607c --- /dev/null +++ b/gfx/2d/FontFeature.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_gfx_FontFeature +#define mozilla_gfx_FontFeature + +#include + +namespace mozilla::gfx { +// An OpenType feature tag and value pair +struct FontFeature { + // see http://www.microsoft.com/typography/otspec/featuretags.htm + uint32_t mTag; + // 0 = off, 1 = on, larger values may be used as parameters + // to features that select among multiple alternatives + uint32_t mValue; +}; + +inline bool operator<(const FontFeature& a, const FontFeature& b) { + return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue)); +} + +inline bool operator==(const FontFeature& a, const FontFeature& b) { + return (a.mTag == b.mTag) && (a.mValue == b.mValue); +} + +} // namespace mozilla::gfx + +#endif diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build index 031ccb1c441d..87d71ea98076 100644 --- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -29,6 +29,7 @@ EXPORTS.mozilla.gfx += [ "DrawTargetRecording.h", "DrawTargetSkia.h", "Filters.h", + "FontFeature.h", "FontVariation.h", "Helpers.h", "HelpersCairo.h", diff --git a/gfx/src/nsFont.h b/gfx/src/nsFont.h index b99290855dd0..4f0e3861859d 100644 --- a/gfx/src/nsFont.h +++ b/gfx/src/nsFont.h @@ -14,7 +14,6 @@ #include "mozilla/StyleColorInlines.h" // for StyleAbsoluteColor #include "nsTArray.h" // for nsTArray -struct gfxFontFeature; struct gfxFontStyle; // Font structure. diff --git a/gfx/thebes/gfxFontEntry.h b/gfx/thebes/gfxFontEntry.h index e6dff76fc8e8..0fd73d037522 100644 --- a/gfx/thebes/gfxFontEntry.h +++ b/gfx/thebes/gfxFontEntry.h @@ -16,6 +16,7 @@ #include "gfxFontVariations.h" #include "gfxRect.h" #include "gfxTypes.h" +#include "gfxFontFeatures.h" #include "harfbuzz/hb.h" #include "mozilla/AlreadyAddRefed.h" #include "mozilla/Assertions.h" @@ -44,7 +45,6 @@ class gfxSVGGlyphs; class gfxUserFontData; class nsAtom; struct FontListSizes; -struct gfxFontFeature; struct gfxFontStyle; enum class eFontPresentation : uint8_t; diff --git a/gfx/thebes/gfxFontFeatures.h b/gfx/thebes/gfxFontFeatures.h index 24ece02d36a8..e8a37d00ebb1 100644 --- a/gfx/thebes/gfxFontFeatures.h +++ b/gfx/thebes/gfxFontFeatures.h @@ -11,24 +11,9 @@ #include "nsTHashtable.h" #include "nsTArray.h" #include "nsString.h" +#include "mozilla/gfx/FontFeature.h" -// An OpenType feature tag and value pair -struct gfxFontFeature { - uint32_t - mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm - uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters - // to features that select among multiple alternatives -}; - -inline bool operator<(const gfxFontFeature& a, const gfxFontFeature& b) { - return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue)); -} - -inline bool operator==(const gfxFontFeature& a, const gfxFontFeature& b) { - return (a.mTag == b.mTag) && (a.mValue == b.mValue); -} - -class nsAtom; +using gfxFontFeature = mozilla::gfx::FontFeature; class gfxFontFeatureValueSet final { public: diff --git a/layout/style/GeckoBindings.h b/layout/style/GeckoBindings.h index 54142ce6ceeb..acb5b24776c8 100644 --- a/layout/style/GeckoBindings.h +++ b/layout/style/GeckoBindings.h @@ -36,6 +36,7 @@ class StyleSheet; enum class PseudoStyleType : uint8_t; enum class PointerCapabilities : uint8_t; enum class UpdateAnimationsTasks : uint8_t; +enum class StyleColorGamut : uint8_t; struct Keyframe; struct StyleStylesheetContents; @@ -44,7 +45,6 @@ class LoaderReusableStyleSheets; } namespace dom { enum class CompositeOperationOrAuto : uint8_t; -enum class ScreenColorGamut : uint8_t; } // namespace dom } // namespace mozilla @@ -583,7 +583,7 @@ bool Gecko_MediaFeatures_UseOverlayScrollbars(const mozilla::dom::Document*); int32_t Gecko_MediaFeatures_GetColorDepth(const mozilla::dom::Document*); int32_t Gecko_MediaFeatures_GetMonochromeBitsPerPixel( const mozilla::dom::Document*); -mozilla::dom::ScreenColorGamut Gecko_MediaFeatures_ColorGamut( +mozilla::StyleColorGamut Gecko_MediaFeatures_ColorGamut( const mozilla::dom::Document*); void Gecko_MediaFeatures_GetDeviceSize(const mozilla::dom::Document*, diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 81307b32cd84..b8e66d8f6025 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -2,20 +2,16 @@ headers = [ "nsStyleStruct.h", "mozilla/StyleAnimationValue.h", - "gfxFontConstants.h", - "gfxFontFeatures.h", - "COLRFonts.h", "nsStyleConsts.h", - "mozilla/css/Loader.h", + "nsCSSValue.h", "mozilla/AnimatedPropertyID.h", "mozilla/css/SheetLoadData.h", "mozilla/DeclarationBlock.h", - "mozilla/dom/AnimationEffectBinding.h", "mozilla/dom/HTMLSlotElement.h", "mozilla/dom/KeyframeEffectBinding.h", "mozilla/dom/MediaList.h", - "mozilla/dom/ScreenBinding.h", "mozilla/dom/ShadowRoot.h", + "mozilla/gfx/FontFeature.h", "mozilla/ipc/ByteBuf.h", "mozilla/AnimationPropertySegment.h", "mozilla/ComputedTiming.h", @@ -88,7 +84,6 @@ rusty-enums = [ "mozilla::Side", "mozilla::dom::PlaybackDirection", "mozilla::dom::FillMode", - "mozilla::dom::ScreenColorGamut", "mozilla::HalfCorner", "mozilla::StyleFloatEdge", "mozilla::StyleShapeRadius", @@ -160,7 +155,6 @@ rusty-enums = [ "mozilla::PseudoStyleType", "mozilla::LookAndFeel_ColorID", "mozilla::LookAndFeel_FontID", - "nsStyleTransformMatrix::MatrixTransformOperator", "mozilla::StyleGeometryBox", "mozilla::SystemColor", "mozilla::StyleMaskMode", @@ -189,6 +183,7 @@ allowlist-vars = [ # TODO(emilio): A bunch of types here can go away once we generate bindings and # structs together. allowlist-types = [ + "nsCSSUnit", "nsFontFaceRuleContainer", "mozilla::ComputedKeyframeValues", "mozilla::Keyframe", @@ -224,13 +219,10 @@ allowlist-types = [ "mozilla::UpdateAnimationsTasks", "mozilla::PointerCapabilities", "mozilla::LookAndFeel", - "mozilla::gfx::Float", + "mozilla::gfx::FontFeature", "mozilla::gfx::FontVariation", "mozilla::gfx::FontPaletteValueSet", "mozilla::StyleImageLayerAttachment", - "gfxFontFeature", - "gfxFontVariation", - "Element", "GeckoFontMetrics", "GeckoImplicitShadowRoot", "gfxFontFeatureValueSet", @@ -248,7 +240,6 @@ allowlist-types = [ "nsCSSPropertyID", "nsCSSPropertyIDSet", "nsCSSProps", - "nsCSSValue", "nsFont", "nsAtom", "nsDynamicAtom", @@ -289,11 +280,20 @@ allowlist-types = [ "mozilla::InheritTarget", "mozilla::dom::MediaList", "mozilla::StyleRuleInclusion", - "nsStyleTransformMatrix::MatrixTransformOperator", "NodeSelectorFlags", ] opaque-types = [ "mozilla::StyleThinArc", # https://github.com/rust-lang/rust-bindgen/issues/1557 + "mozilla::gfx::.*Point", + "mozilla::gfx::.*Rect", + "mozilla::gfx::.*Size", + "mozilla::gfx::.*Margin", + "mozilla::gfx::.*Matrix", + "mozilla::gfx::.*Typed", + "mozilla::gfx::Matrix4x4TypedFlagged", + "mozilla::gfx::DrawTarget", + "mozilla::TouchManager", + "mozilla::CanvasUsage", "std::pair__PCCP", "std::namespace::atomic___base", "std::atomic__My_base", "std::atomic", @@ -301,9 +301,7 @@ opaque-types = [ "std::tuple.*", # Causes "Cannot find type _Pred in this scope" error on mac, like rust-skia#571 "std::.*::tuple.*", - # We want everything but FontVariation and Float to be opaque but we don't - # have negative regexes. - "mozilla::gfx::(.{0,4}|.{6,12}|.{14,}|([^F][^o][^n][^t][^V][^a][^r][^i][^a][^t][^i][^o][^n])|([^F][^l][^o][^a][^t]))", + "mozilla::dom::Touch", "mozilla::dom::Sequence", "mozilla::SmallPointerArray", "mozilla::dom::Optional", @@ -368,6 +366,7 @@ cbindgen-types = [ { gecko = "StyleComputedFontWeightRange", servo = "crate::font_face::ComputedFontWeightRange" }, { gecko = "StyleComputedTimingFunction", servo = "crate::values::computed::easing::TimingFunction" }, { gecko = "StylePrefersContrast", servo = "crate::gecko::media_features::PrefersContrast" }, + { gecko = "StyleColorGamut", servo = "crate::gecko::media_features::ColorGamut" }, { gecko = "StyleCursorKind", servo = "crate::values::computed::ui::CursorKind" }, { gecko = "StyleDisplay", servo = "crate::values::specified::Display" }, { gecko = "StyleDisplayMode", servo = "crate::gecko::media_features::DisplayMode" }, diff --git a/layout/style/ServoStyleConstsForwards.h b/layout/style/ServoStyleConstsForwards.h index cd2958618f63..d6c5ec089e59 100644 --- a/layout/style/ServoStyleConstsForwards.h +++ b/layout/style/ServoStyleConstsForwards.h @@ -46,14 +46,15 @@ class imgRequestProxy; struct nsCSSValueSharedList; class gfxFontFeatureValueSet; -struct gfxFontFeature; struct GeckoFontMetrics; namespace mozilla { namespace gfx { struct FontVariation; +struct FontFeature; } // namespace gfx } // namespace mozilla -typedef mozilla::gfx::FontVariation gfxFontVariation; +using gfxFontVariation = mozilla::gfx::FontVariation; +using gfxFontFeature = mozilla::gfx::FontFeature; enum nsCSSUnit : uint32_t; enum nsChangeHint : uint32_t; diff --git a/layout/style/StyleAnimationValue.h b/layout/style/StyleAnimationValue.h index 85719ae4f621..fe858aa0bea7 100644 --- a/layout/style/StyleAnimationValue.h +++ b/layout/style/StyleAnimationValue.h @@ -9,23 +9,16 @@ #ifndef mozilla_StyleAnimationValue_h_ #define mozilla_StyleAnimationValue_h_ -#include "mozilla/gfx/MatrixFwd.h" -#include "mozilla/gfx/Point.h" #include "mozilla/RefPtr.h" #include "mozilla/ServoBindingTypes.h" #include "mozilla/ServoStyleConsts.h" // Servo_AnimationValue_Dump -#include "mozilla/DbgMacro.h" #include "mozilla/AnimatedPropertyID.h" #include "nsStringFwd.h" -#include "nsCoord.h" #include "nsColor.h" #include "nsCSSPropertyID.h" -#include "nsCSSValue.h" -#include "nsStyleConsts.h" #include "nsStyleTransformMatrix.h" class nsIFrame; -class gfx3DMatrix; namespace mozilla { diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index 540ac91a4997..2c80a3f47739 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -9,34 +9,12 @@ #ifndef nsCSSValue_h___ #define nsCSSValue_h___ -#include "mozilla/Attributes.h" -#include "mozilla/CORSMode.h" -#include "mozilla/EnumTypeTraits.h" -#include "mozilla/MemoryReporting.h" -#include "mozilla/ServoBindingTypes.h" -#include "mozilla/URLExtraData.h" -#include "mozilla/UniquePtr.h" - #include "nsCoord.h" -#include "nsTArray.h" -#include - -// XXX Avoid including this here by moving function bodies to the cpp file -#include "mozilla/FloatingPoint.h" - -class imgRequestProxy; -class nsAtom; -class nsIContent; - -class nsIPrincipal; -class nsIURI; -class nsPresContext; -template -class nsPtrHashKey; struct RawServoCssUrlData; namespace mozilla { +struct URLExtraData; class CSSStyleSheet; } // namespace mozilla diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index cc86d1abf6cc..94f01a53378c 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -142,15 +142,20 @@ int32_t Gecko_MediaFeatures_GetMonochromeBitsPerPixel( return color ? 0 : kDefaultMonochromeBpp; } -dom::ScreenColorGamut Gecko_MediaFeatures_ColorGamut( - const Document* aDocument) { - auto colorGamut = dom::ScreenColorGamut::Srgb; - if (!aDocument->ShouldResistFingerprinting(RFPTarget::CSSColorInfo)) { - if (auto* dx = GetDeviceContextFor(aDocument)) { - colorGamut = dx->GetColorGamut(); - } +StyleColorGamut Gecko_MediaFeatures_ColorGamut(const Document* aDocument) { + auto* dx = GetDeviceContextFor(aDocument); + if (!dx || aDocument->ShouldResistFingerprinting(RFPTarget::CSSColorInfo)) { + return StyleColorGamut::Srgb; } - return colorGamut; + switch (dx->GetColorGamut()) { + case dom::ScreenColorGamut::Srgb: + return StyleColorGamut::Srgb; + case dom::ScreenColorGamut::Rec2020: + return StyleColorGamut::Rec2020; + case dom::ScreenColorGamut::P3: + return StyleColorGamut::P3; + } + return StyleColorGamut::Srgb; } int32_t Gecko_MediaFeatures_GetColorDepth(const Document* aDocument) { diff --git a/layout/style/nsStyleTransformMatrix.cpp b/layout/style/nsStyleTransformMatrix.cpp index 71f8f826c2a5..5aa670eefb54 100644 --- a/layout/style/nsStyleTransformMatrix.cpp +++ b/layout/style/nsStyleTransformMatrix.cpp @@ -280,7 +280,7 @@ class Accumulate { static Matrix4x4 operateByServo(const Matrix4x4& aMatrix1, const Matrix4x4& aMatrix2, double aCount) { Matrix4x4 result; - Servo_MatrixTransform_Operate(MatrixTransformOperator::Accumulate, + Servo_MatrixTransform_Operate(/* aInterpolate = */ false, &aMatrix1.components, &aMatrix2.components, aCount, &result.components); return result; @@ -318,7 +318,7 @@ class Interpolate { static Matrix4x4 operateByServo(const Matrix4x4& aMatrix1, const Matrix4x4& aMatrix2, double aProgress) { Matrix4x4 result; - Servo_MatrixTransform_Operate(MatrixTransformOperator::Interpolate, + Servo_MatrixTransform_Operate(/* aInterpolate = */ true, &aMatrix1.components, &aMatrix2.components, aProgress, &result.components); return result; diff --git a/layout/style/nsStyleUtil.h b/layout/style/nsStyleUtil.h index 990996fdbc3e..cfcd2f1df0d6 100644 --- a/layout/style/nsStyleUtil.h +++ b/layout/style/nsStyleUtil.h @@ -18,7 +18,6 @@ class nsCSSValue; class nsIContent; class nsIPrincipal; class nsIURI; -struct gfxFontFeature; struct nsCSSKTableEntry; struct nsCSSValueList; struct nsStylePosition; diff --git a/servo/components/style/gecko/media_features.rs b/servo/components/style/gecko/media_features.rs index 26c19be6e915..19d536fadc74 100644 --- a/servo/components/style/gecko/media_features.rs +++ b/servo/components/style/gecko/media_features.rs @@ -6,7 +6,6 @@ use crate::gecko_bindings::bindings; use crate::gecko_bindings::structs; -use crate::gecko_bindings::structs::ScreenColorGamut; use crate::media_queries::{Device, MediaType}; use crate::parser::ParserContext; use crate::queries::feature::{AllowsRanges, Evaluator, FeatureFlags, QueryFeatureDescription}; @@ -150,7 +149,7 @@ fn eval_monochrome(context: &Context) -> i32 { /// higher capabilities. #[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, PartialOrd, ToCss)] #[repr(u8)] -enum ColorGamut { +pub enum ColorGamut { /// The sRGB gamut. Srgb, /// The gamut specified by the Display P3 Color Space. @@ -168,12 +167,7 @@ fn eval_color_gamut(context: &Context, query_value: Option) -> bool let color_gamut = unsafe { bindings::Gecko_MediaFeatures_ColorGamut(context.device().document()) }; // Match if our color gamut is at least as wide as the query value - query_value <= - match color_gamut { - ScreenColorGamut::Srgb => ColorGamut::Srgb, - ScreenColorGamut::P3 => ColorGamut::P3, - ScreenColorGamut::Rec2020 => ColorGamut::Rec2020, - } + query_value <= color_gamut } /// https://drafts.csswg.org/mediaqueries-4/#resolution diff --git a/servo/ports/geckolib/cbindgen.toml b/servo/ports/geckolib/cbindgen.toml index e56bcbb0ad66..ad5589347fc1 100644 --- a/servo/ports/geckolib/cbindgen.toml +++ b/servo/ports/geckolib/cbindgen.toml @@ -105,6 +105,7 @@ include = [ "BoolInteger", "OutlineStyle", "CaptionSide", + "ColorGamut", "FontSizeAdjust", "FontPalette", "FontLanguageOverride", diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 2eeaae4a6e27..3f47cfeaed80 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -67,7 +67,6 @@ use style::gecko_bindings::structs::nsCSSFontDesc; use style::gecko_bindings::structs::nsCSSPropertyID; use style::gecko_bindings::structs::nsChangeHint; use style::gecko_bindings::structs::nsCompatibility; -use style::gecko_bindings::structs::nsStyleTransformMatrix::MatrixTransformOperator; use style::gecko_bindings::structs::nsresult; use style::gecko_bindings::structs::CallerType; use style::gecko_bindings::structs::CompositeOperation; @@ -4768,28 +4767,24 @@ pub extern "C" fn Servo_GetProperties_Overriding_Animation( #[no_mangle] pub extern "C" fn Servo_MatrixTransform_Operate( - matrix_operator: MatrixTransformOperator, - from: *const structs::Matrix4x4Components, - to: *const structs::Matrix4x4Components, + interpolate: bool, + from: &structs::Matrix4x4Components, + to: &structs::Matrix4x4Components, progress: f64, - output: *mut structs::Matrix4x4Components, + output: &mut structs::Matrix4x4Components, ) { - use self::MatrixTransformOperator::{Accumulate, Interpolate}; use style::values::computed::transform::Matrix3D; - let from = Matrix3D::from(unsafe { from.as_ref() }.expect("not a valid 'from' matrix")); - let to = Matrix3D::from(unsafe { to.as_ref() }.expect("not a valid 'to' matrix")); - let result = match matrix_operator { - Interpolate => from.animate(&to, Procedure::Interpolate { progress }), - Accumulate => from.animate( - &to, - Procedure::Accumulate { - count: progress as u64, - }, - ), + let from = Matrix3D::from(from); + let to = Matrix3D::from(to); + let proc = if interpolate { + Procedure::Interpolate { progress } + } else { + Procedure::Accumulate { + count: progress as u64, + } }; - - let output = unsafe { output.as_mut() }.expect("not a valid 'output' matrix"); + let result = from.animate(&to, proc); if let Ok(result) = result { *output = result.into(); } else if progress < 0.5 {