Bug 1799258 - Fix constexpr issue on base toolchain builds. r=gfx-reviewers,lsalzman
[gecko.git] / gfx / thebes / COLRFonts.h
bloba073bb416462c25e2154cd77c8c124f9d1f16a05
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef COLR_FONTS_H
7 #define COLR_FONTS_H
9 #include "mozilla/gfx/2D.h"
10 #include "mozilla/UniquePtr.h"
11 #include "nsAtom.h"
12 #include "nsTArray.h"
13 #include "nsTHashtable.h"
15 struct hb_blob_t;
16 struct hb_face_t;
17 struct hb_font_t;
19 namespace mozilla {
21 namespace layout {
22 class TextDrawTarget;
25 namespace gfx {
27 class FontPaletteValueSet {
28 public:
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FontPaletteValueSet)
31 struct OverrideColor {
32 uint32_t mIndex = 0;
33 sRGBColor mColor;
36 struct PaletteValues {
37 enum { kLight = -1, kDark = -2 };
38 int32_t mBasePalette = 0; // 0-based index, or kLight/kDark constants
39 nsTArray<OverrideColor> mOverrides;
42 const PaletteValues* Lookup(nsAtom* aName, const nsACString& aFamily) const;
44 PaletteValues* Insert(nsAtom* aName, const nsACString& aFamily);
46 private:
47 ~FontPaletteValueSet() = default;
49 struct PaletteHashKey {
50 RefPtr<nsAtom> mName;
51 nsCString mFamily;
53 PaletteHashKey() = delete;
54 PaletteHashKey(nsAtom* aName, const nsACString& aFamily)
55 : mName(aName), mFamily(aFamily) {}
56 PaletteHashKey(const PaletteHashKey& aKey) = default;
59 class HashEntry : public PLDHashEntryHdr {
60 public:
61 using KeyType = const PaletteHashKey&;
62 using KeyTypePointer = const PaletteHashKey*;
64 HashEntry() = delete;
65 explicit HashEntry(KeyTypePointer aKey) : mKey(*aKey) {}
66 HashEntry(HashEntry&& other) noexcept
67 : PLDHashEntryHdr(std::move(other)),
68 mKey(other.mKey),
69 mValue(std::move(other.mValue)) {
70 NS_ERROR("Should not be called");
72 ~HashEntry() = default;
74 bool KeyEquals(const KeyTypePointer aKey) const {
75 return mKey.mName == aKey->mName && mKey.mFamily.Equals(aKey->mFamily);
77 static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
78 static PLDHashNumber HashKey(const KeyTypePointer aKey) {
79 return aKey->mName->hash() +
80 HashString(aKey->mFamily.get(), aKey->mFamily.Length());
82 enum { ALLOW_MEMMOVE = true };
84 PaletteHashKey mKey;
85 PaletteValues mValue;
88 nsTHashtable<HashEntry> mValues;
91 class COLRFonts {
92 public:
93 static bool ValidateColorGlyphs(hb_blob_t* aCOLR, hb_blob_t* aCPAL);
95 // COLRv0: color glyph is represented as a simple list of colored layers.
96 // (This is used only as an opaque pointer; the internal type is private.)
97 struct GlyphLayers;
99 static const GlyphLayers* GetGlyphLayers(hb_blob_t* aCOLR, uint32_t aGlyphId);
101 static bool PaintGlyphLayers(
102 hb_blob_t* aCOLR, hb_face_t* aFace, const GlyphLayers* aLayers,
103 DrawTarget* aDrawTarget, layout::TextDrawTarget* aTextDrawer,
104 ScaledFont* aScaledFont, DrawOptions aDrawOptions, const Point& aPoint,
105 const sRGBColor& aCurrentColor, const nsTArray<sRGBColor>* aColors);
107 // COLRv1 support: color glyph is represented by a directed acyclic graph of
108 // paint records.
109 // (This is used only as an opaque pointer; the internal type is private.)
110 struct GlyphPaintGraph;
112 static const GlyphPaintGraph* GetGlyphPaintGraph(hb_blob_t* aCOLR,
113 uint32_t aGlyphId);
115 static bool PaintGlyphGraph(
116 hb_blob_t* aCOLR, hb_font_t* aFont, const GlyphPaintGraph* aPaintGraph,
117 DrawTarget* aDrawTarget, layout::TextDrawTarget* aTextDrawer,
118 ScaledFont* aScaledFont, DrawOptions aDrawOptions, const Point& aPoint,
119 const sRGBColor& aCurrentColor, const nsTArray<sRGBColor>* aColors,
120 uint32_t aGlyphId, float aFontUnitsToPixels);
122 static Rect GetColorGlyphBounds(hb_blob_t* aCOLR, hb_font_t* aFont,
123 uint32_t aGlyphId, DrawTarget* aDrawTarget,
124 ScaledFont* aScaledFont,
125 float aFontUnitsToPixels);
127 static uint16_t GetColrTableVersion(hb_blob_t* aCOLR);
129 static UniquePtr<nsTArray<sRGBColor>> SetupColorPalette(
130 hb_face_t* aFace, const FontPaletteValueSet* aPaletteValueSet,
131 nsAtom* aFontPalette, const nsACString& aFamilyName);
134 } // namespace gfx
136 } // namespace mozilla
138 #endif // COLR_FONTS_H