Remove refcounting from CFPF_SkiaFont.
The refcounting is useless, since CFPF_SkiaFontMgr always has a
reference to the fonts anyway. Just make CFPF_SkiaFontMgr own the fonts,
like on other platforms.
Change-Id: Ifadb5c4e09f151ada4a0a68e0588166c2f2974d4
Reviewed-on: https://pdfium-review.googlesource.com/40610
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp
index 2d9f274..2d4ff68 100644
--- a/core/fxge/android/cfpf_skiafont.cpp
+++ b/core/fxge/android/cfpf_skiafont.cpp
@@ -30,16 +30,6 @@
FXFT_Done_Face(m_Face);
}
-void CFPF_SkiaFont::Release() {
- if (--m_dwRefCount == 0)
- delete this;
-}
-
-CFPF_SkiaFont* CFPF_SkiaFont::Retain() {
- m_dwRefCount++;
- return this;
-}
-
ByteString CFPF_SkiaFont::GetFamilyName() {
if (!m_Face)
return ByteString();
diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h
index 4e3b02d..0dfb14b 100644
--- a/core/fxge/android/cfpf_skiafont.h
+++ b/core/fxge/android/cfpf_skiafont.h
@@ -20,9 +20,7 @@
const CFPF_SkiaPathFont* pFont,
uint32_t dwStyle,
uint8_t uCharset);
-
- void Release();
- CFPF_SkiaFont* Retain();
+ ~CFPF_SkiaFont();
bool IsValid() const { return !!m_Face; }
@@ -41,14 +39,11 @@
uint32_t GetFontData(uint32_t dwTable, uint8_t* pBuffer, uint32_t dwSize);
private:
- ~CFPF_SkiaFont();
-
UnownedPtr<CFPF_SkiaFontMgr> const m_pFontMgr;
UnownedPtr<const CFPF_SkiaPathFont> const m_pFont;
const FXFT_Face m_Face;
const uint32_t m_dwStyle;
const uint8_t m_uCharset;
- uint32_t m_dwRefCount = 0;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index cd6aab1..f9afdab 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -7,6 +7,7 @@
#include "core/fxge/android/cfpf_skiafontmgr.h"
#include <algorithm>
+#include <utility>
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
@@ -228,9 +229,6 @@
CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() = default;
CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() {
- for (const auto& pair : m_FamilyFonts)
- pair.second->Release();
-
m_FamilyFonts.clear();
m_FontFaces.clear();
if (m_FTLibrary)
@@ -256,7 +254,7 @@
uint32_t dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
auto it = m_FamilyFonts.find(dwHash);
if (it != m_FamilyFonts.end())
- return it->second->Retain();
+ return it->second.get();
uint32_t dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
uint32_t dwSubst = FPF_SkiaGetSubstFont(dwFaceName, g_SkiaFontmap,
@@ -319,17 +317,17 @@
break;
}
}
- if (pBestFont) {
- CFPF_SkiaFont* pFont =
- new CFPF_SkiaFont(this, pBestFont, dwStyle, uCharset);
- pFont->Retain();
- if (pFont->IsValid()) {
- m_FamilyFonts[dwHash] = pFont;
- return pFont;
- }
- pFont->Release();
- }
- return nullptr;
+ if (!pBestFont)
+ return nullptr;
+
+ auto pFont =
+ pdfium::MakeUnique<CFPF_SkiaFont>(this, pBestFont, dwStyle, uCharset);
+ if (!pFont->IsValid())
+ return nullptr;
+
+ CFPF_SkiaFont* pRet = pFont.get();
+ m_FamilyFonts[dwHash] = std::move(pFont);
+ return pRet;
}
FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const ByteStringView& bsFile,
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index 2c7d867..a5ad5b4 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -39,7 +39,7 @@
bool m_bLoaded = false;
FXFT_Library m_FTLibrary = nullptr;
std::vector<std::unique_ptr<CFPF_SkiaPathFont>> m_FontFaces;
- std::map<uint32_t, CFPF_SkiaFont*> m_FamilyFonts;
+ std::map<uint32_t, std::unique_ptr<CFPF_SkiaFont>> m_FamilyFonts;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp
index 2077641..2b3b42c 100644
--- a/core/fxge/android/cfx_androidfontinfo.cpp
+++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -77,9 +77,4 @@
return false;
}
-void CFX_AndroidFontInfo::DeleteFont(void* hFont) {
- if (!hFont)
- return;
-
- static_cast<CFPF_SkiaFont*>(hFont)->Release();
-}
+void CFX_AndroidFontInfo::DeleteFont(void* hFont) {}