Bug 1611043 - Convert mask-type #defines to an enum class. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D60987

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin McNickle 2020-01-27 14:59:41 +00:00
parent d551a31fb6
commit 0c665c265e
6 changed files with 17 additions and 25 deletions

View File

@ -140,6 +140,7 @@ rusty-enums = [
"mozilla::StyleFlexWrap",
"mozilla::StyleTextDecorationSkipInk",
"mozilla::StyleTextDecorationLength",
"mozilla::StyleMaskType",
"mozilla::StyleShapeRendering",
"mozilla::StyleTextAnchor",
"mozilla::StyleObjectFit",

View File

@ -751,8 +751,10 @@ enum class StyleDominantBaseline : uint8_t {
#define NS_STYLE_IMAGE_RENDERING_CRISP_EDGES 3
// mask-type
#define NS_STYLE_MASK_TYPE_LUMINANCE 0
#define NS_STYLE_MASK_TYPE_ALPHA 1
enum class StyleMaskType : uint8_t {
Luminance,
Alpha,
};
// shape-rendering
enum class StyleShapeRendering : uint8_t {

View File

@ -1057,7 +1057,7 @@ nsStyleSVGReset::nsStyleSVGReset(const Document& aDocument)
mStopOpacity(1.0f),
mFloodOpacity(1.0f),
mVectorEffect(NS_STYLE_VECTOR_EFFECT_NONE),
mMaskType(NS_STYLE_MASK_TYPE_LUMINANCE) {
mMaskType(StyleMaskType::Luminance) {
MOZ_COUNT_CTOR(nsStyleSVGReset);
}

View File

@ -2204,7 +2204,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset {
float mFloodOpacity;
uint8_t mVectorEffect; // NS_STYLE_VECTOR_EFFECT_*
uint8_t mMaskType; // NS_STYLE_MASK_TYPE_*
mozilla::StyleMaskType mMaskType;
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects {

View File

@ -24,19 +24,6 @@ using namespace mozilla::dom::SVGUnitTypes_Binding;
using namespace mozilla::gfx;
using namespace mozilla::image;
static LuminanceType GetLuminanceType(uint8_t aNSMaskType) {
switch (aNSMaskType) {
case NS_STYLE_MASK_TYPE_LUMINANCE:
return LuminanceType::LUMINANCE;
case NS_STYLE_COLOR_INTERPOLATION_LINEARRGB:
return LuminanceType::LINEARRGB;
default: {
NS_WARNING("Unknown SVG mask type, defaulting to luminance");
return LuminanceType::LUMINANCE;
}
}
}
nsIFrame* NS_NewSVGMaskFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
return new (aPresShell) nsSVGMaskFrame(aStyle, aPresShell->GetPresContext());
}
@ -66,17 +53,17 @@ already_AddRefed<SourceSurface> nsSVGMaskFrame::GetMaskForMaskedFrame(
Rect maskSurfaceRect = ToRect(maskSurfaceRectDouble);
maskSurfaceRect.RoundOut();
uint8_t maskType;
StyleMaskType maskType;
if (aParams.maskMode == StyleMaskMode::MatchSource) {
maskType = StyleSVGReset()->mMaskType;
} else {
maskType = aParams.maskMode == StyleMaskMode::Luminance
? NS_STYLE_MASK_TYPE_LUMINANCE
: NS_STYLE_MASK_TYPE_ALPHA;
? StyleMaskType::Luminance
: StyleMaskType::Alpha;
}
RefPtr<DrawTarget> maskDT;
if (maskType == NS_STYLE_MASK_TYPE_LUMINANCE) {
if (maskType == StyleMaskType::Luminance) {
maskDT = context->GetDrawTarget()->CreateClippedDrawTarget(
maskSurfaceRect, SurfaceFormat::B8G8R8A8);
} else {
@ -109,14 +96,15 @@ already_AddRefed<SourceSurface> nsSVGMaskFrame::GetMaskForMaskedFrame(
}
RefPtr<SourceSurface> surface;
if (maskType == NS_STYLE_MASK_TYPE_LUMINANCE) {
if (maskType == StyleMaskType::Luminance) {
auto luminanceType = LuminanceType::LUMINANCE;
if (StyleSVG()->mColorInterpolation ==
NS_STYLE_COLOR_INTERPOLATION_LINEARRGB) {
maskType = NS_STYLE_COLOR_INTERPOLATION_LINEARRGB;
luminanceType = LuminanceType::LINEARRGB;
}
RefPtr<SourceSurface> maskSnapshot = maskDT->IntoLuminanceSource(
GetLuminanceType(maskType), aParams.opacity);
RefPtr<SourceSurface> maskSnapshot =
maskDT->IntoLuminanceSource(luminanceType, aParams.opacity);
if (!maskSnapshot) {
return nullptr;
}

View File

@ -69,6 +69,7 @@ ${helpers.single_keyword(
"mask-type",
"luminance alpha",
engines="gecko",
gecko_enum_prefix="StyleMaskType",
animation_value_type="discrete",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-type",
)}