Bug 1622360 - Unwind super sketchy changes to glyph atlas code. r=jrmuizel

Depends on D68863

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kartikaya Gupta 2020-04-01 13:40:00 +00:00
parent 0fc597f2c2
commit 30d30f9300
2 changed files with 8 additions and 20 deletions

View File

@ -164,12 +164,7 @@ class WRUserData : public layers::LayerUserData,
static UserDataKey sWRUserDataKey;
};
// If we add more render roots, this will need to be updated to accomodate
// more than two render roots, at which point simply adding a bit to an
// array index is probably not how we want to do things.
static const int CONTENT_RECT_GLYPH_ATLAS = 8;
static RefPtr<SourceSurface> gWRGlyphAtlas[16];
static RefPtr<SourceSurface> gWRGlyphAtlas[8];
static LinkedList<WRUserData> gWRUsers;
UserDataKey WRUserData::sWRUserDataKey;
@ -224,14 +219,12 @@ static void PurgeWRGlyphAtlas() {
// from the layer manager.
for (WRUserData* user : gWRUsers) {
auto* manager = user->mManager;
for (size_t i = 0; i < 16; i++) {
for (size_t i = 0; i < 8; i++) {
if (gWRGlyphAtlas[i]) {
uint32_t handle = (uint32_t)(uintptr_t)gWRGlyphAtlas[i]->GetUserData(
reinterpret_cast<UserDataKey*>(manager));
if (handle) {
wr::RenderRoot renderRoot = (i & CONTENT_RECT_GLYPH_ATLAS)
? wr::RenderRoot::Content
: wr::RenderRoot::Default;
wr::RenderRoot renderRoot = wr::RenderRoot::Default;
manager->GetRenderRootStateManager(renderRoot)
->AddImageKeyForDiscard(
wr::ImageKey{manager->WrBridge()->GetNamespace(), handle});
@ -245,7 +238,7 @@ static void PurgeWRGlyphAtlas() {
gWRUsers.popFirst()->Remove();
}
// Finally, clear out the atlases.
for (size_t i = 0; i < 16; i++) {
for (size_t i = 0; i < 8; i++) {
gWRGlyphAtlas[i] = nullptr;
}
}
@ -259,7 +252,7 @@ WRUserData::~WRUserData() {
// When the layer manager is destroyed, we need go through each
// atlas and remove any assigned image keys.
if (isInList()) {
for (size_t i = 0; i < 16; i++) {
for (size_t i = 0; i < 8; i++) {
if (gWRGlyphAtlas[i]) {
gWRGlyphAtlas[i]->RemoveUserData(
reinterpret_cast<UserDataKey*>(mManager));
@ -279,12 +272,6 @@ static already_AddRefed<SourceSurface> GetWRGlyphAtlas(DrawTarget& aDrawTarget,
key |= (aMat->_11 < 0 ? 1 : 0) | (aMat->_22 < 0 ? 2 : 0);
}
}
// The atlas may exist, but an image key may not be assigned for it to
// the given layer manager.
auto* tdt = static_cast<layout::TextDrawTarget*>(&aDrawTarget);
if (tdt->GetRenderRoot() == wr::RenderRoot::Content) {
key |= CONTENT_RECT_GLYPH_ATLAS;
}
// Check if an atlas was already created, or create one if necessary.
RefPtr<SourceSurface> atlas = gWRGlyphAtlas[key];
@ -293,6 +280,9 @@ static already_AddRefed<SourceSurface> GetWRGlyphAtlas(DrawTarget& aDrawTarget,
gWRGlyphAtlas[key] = atlas;
}
// The atlas may exist, but an image key may not be assigned for it to
// the given layer manager.
auto* tdt = static_cast<layout::TextDrawTarget*>(&aDrawTarget);
auto* manager = tdt->WrLayerManager();
if (!atlas->GetUserData(reinterpret_cast<UserDataKey*>(manager))) {
// No image key, so we need to map the atlas' data for transfer to WR.

View File

@ -123,8 +123,6 @@ class TextDrawTarget : public DrawTarget {
return true;
}
wr::RenderRoot GetRenderRoot() { return mResources->GetRenderRoot(); }
wr::FontInstanceFlags GetWRGlyphFlags() const { return mWRGlyphFlags; }
void SetWRGlyphFlags(wr::FontInstanceFlags aFlags) { mWRGlyphFlags = aFlags; }