forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1872545 - Hoist color-font palette cache out of TextRunDrawParams…
… to the nsPresContext or CanvasRenderingContext2D, for greater effectiveness. r=gfx-reviewers,lsalzman Differential Revision: https://phabricator.services.mozilla.com/D197463
- Loading branch information
Showing
15 changed files
with
163 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* -*- 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" | ||
|
||
using namespace mozilla; | ||
|
||
void gfx::PaletteCache::SetPaletteValueSet( | ||
const gfx::FontPaletteValueSet* aSet) { | ||
mPaletteValueSet = aSet; | ||
Clear(); | ||
} | ||
|
||
nsTArray<gfx::sRGBColor>* 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 = gfx::COLRFonts::SetupColorPalette( | ||
face, mPaletteValueSet, aPaletteName, aFontEntry->FamilyName()); | ||
|
||
entry.Set(std::move(newData)); | ||
} | ||
return entry.Data().mPalette.get(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* -*- 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 FONT_PALETTE_CACHE_H | ||
#define FONT_PALETTE_CACHE_H | ||
|
||
#include "gfxFontEntry.h" | ||
#include "mozilla/gfx/Types.h" | ||
#include "mozilla/MruCache.h" | ||
#include "mozilla/HashFunctions.h" | ||
#include "nsAtom.h" | ||
#include <utility> | ||
|
||
namespace mozilla::gfx { | ||
|
||
class FontPaletteValueSet; | ||
|
||
// MRU cache used for resolved color-font palettes, to avoid reconstructing | ||
// the palette for each glyph rendered with a given font. | ||
using CacheKey = std::pair<RefPtr<gfxFontEntry>, RefPtr<nsAtom>>; | ||
struct CacheData { | ||
CacheKey mKey; | ||
mozilla::UniquePtr<nsTArray<mozilla::gfx::sRGBColor>> mPalette; | ||
}; | ||
|
||
class PaletteCache | ||
: public mozilla::MruCache<CacheKey, CacheData, PaletteCache> { | ||
public: | ||
explicit PaletteCache(const FontPaletteValueSet* aPaletteValueSet = nullptr) | ||
: mPaletteValueSet(aPaletteValueSet) {} | ||
|
||
void SetPaletteValueSet(const FontPaletteValueSet* aSet); | ||
|
||
nsTArray<mozilla::gfx::sRGBColor>* GetPaletteFor(gfxFontEntry* aFontEntry, | ||
nsAtom* aPaletteName); | ||
|
||
static mozilla::HashNumber Hash(const CacheKey& aKey) { | ||
return mozilla::HashGeneric(aKey.first.get(), aKey.second.get()); | ||
} | ||
static bool Match(const CacheKey& aKey, const CacheData& aVal) { | ||
return aVal.mKey == aKey; | ||
} | ||
|
||
protected: | ||
const FontPaletteValueSet* mPaletteValueSet = nullptr; | ||
}; | ||
|
||
} // namespace mozilla::gfx | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.