summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/FontPaletteCache.cpp
blob: 02ca74097794d4f733de48b13ef56bc222f25869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* -*- 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/. */

#include "FontPaletteCache.h"
#include "COLRFonts.h"
#include "gfxFontEntry.h"

using namespace mozilla;

void gfx::PaletteCache::SetPaletteValueSet(
    const gfx::FontPaletteValueSet* aSet) {
  mPaletteValueSet = aSet;
  Clear();
}

already_AddRefed<gfx::FontPalette> gfx::PaletteCache::GetPaletteFor(
    gfxFontEntry* aFontEntry, nsAtom* aPaletteName) {
  auto entry = Lookup(std::pair(aFontEntry, aPaletteName));
  if (!entry) {
    CacheData newData;
    newData.mKey = std::pair(aFontEntry, aPaletteName);

    gfxFontEntry::AutoHBFace face = aFontEntry->GetHBFace();
    newData.mPalette = new FontPalette(gfx::COLRFonts::CreateColorPalette(
        face, mPaletteValueSet, aPaletteName, aFontEntry->FamilyName()));

    entry.Set(std::move(newData));
  }
  RefPtr result = entry.Data().mPalette;
  return result.forget();
}