Bug 1964823 - Replace AutoCFRelease by AutoCFTypeRef r=media-playback-reviewers,padenot

This patch replaces all the `AutoCFRelease<T>` by `AutoCFTypeRef<T>`.

Differential Revision: https://phabricator.services.mozilla.com/D248141
This commit is contained in:
CM
2025-05-08 19:05:00 +00:00
committed by cchang@mozilla.com
parent c8711878f8
commit 52e6d4ef33
5 changed files with 116 additions and 188 deletions

View File

@@ -27,76 +27,6 @@ inline bool OSSupportsSVC() {
namespace mozilla {
// Wrapper class to call CFRelease/CVBufferRelease on reference types
// when they go out of scope.
template <class T, class F, F relFunc>
class AutoObjRefRelease {
public:
MOZ_IMPLICIT AutoObjRefRelease(T aRef) : mRef(aRef) {}
~AutoObjRefRelease() {
if (mRef) {
relFunc(mRef);
}
}
// Return the wrapped ref so it can be used as an in parameter.
operator T() { return mRef; }
// Return a pointer to the wrapped ref for use as an out parameter.
T* receive() { return &mRef; }
private:
// Copy operator isn't supported and is not implemented.
AutoObjRefRelease<T, F, relFunc>& operator=(
const AutoObjRefRelease<T, F, relFunc>&);
T mRef;
};
template <typename T>
using AutoCFRelease = AutoObjRefRelease<T, decltype(&CFRelease), &CFRelease>;
template <typename T>
using AutoCVBufferRelease =
AutoObjRefRelease<T, decltype(&CVBufferRelease), &CVBufferRelease>;
// CFRefPtr: A CoreFoundation smart pointer.
template <class T>
class CFRefPtr {
public:
explicit CFRefPtr(T aRef) : mRef(aRef) {
if (mRef) {
CFRetain(mRef);
}
}
// Copy constructor.
CFRefPtr(const CFRefPtr<T>& aCFRefPtr) : mRef(aCFRefPtr.mRef) {
if (mRef) {
CFRetain(mRef);
}
}
// Copy operator
CFRefPtr<T>& operator=(const CFRefPtr<T>& aCFRefPtr) {
if (mRef == aCFRefPtr.mRef) {
return;
}
if (mRef) {
CFRelease(mRef);
}
mRef = aCFRefPtr.mRef;
if (mRef) {
CFRetain(mRef);
}
return *this;
}
~CFRefPtr() {
if (mRef) {
CFRelease(mRef);
}
}
// Return the wrapped ref so it can be used as an in parameter.
operator T() { return mRef; }
private:
T mRef;
};
template <typename T>
struct AutoTypeRefTraits;

View File

@@ -511,7 +511,7 @@ CGFontRef CTFontEntry::CreateOrCopyFontRef() {
CrashReporter::Annotation::FontName, mName);
// Create a new CGFont; caller will own the only reference to it.
AutoCFRelease<CFStringRef> psname = CreateCFStringForString(mName);
AutoCFTypeRef<CFStringRef> psname(CreateCFStringForString(mName));
if (!psname) {
return nullptr;
}
@@ -549,7 +549,7 @@ class FontTableRec {
hb_blob_t* CTFontEntry::GetFontTable(uint32_t aTag) {
mLock.ReadLock();
AutoCFRelease<CGFontRef> fontRef = CreateOrCopyFontRef();
AutoCFTypeRef<CGFontRef> fontRef(CreateOrCopyFontRef());
mLock.ReadUnlock();
if (!fontRef) {
return nullptr;
@@ -582,11 +582,11 @@ bool CTFontEntry::HasFontTable(uint32_t aTableTag) {
AutoWriteLock lock(mLock);
if (mAvailableTables.Count() == 0) {
AutoCFRelease<CGFontRef> fontRef = CreateOrCopyFontRef();
AutoCFTypeRef<CGFontRef> fontRef(CreateOrCopyFontRef());
if (!fontRef) {
return false;
}
AutoCFRelease<CFArrayRef> tags = ::CGFontCopyTableTags(fontRef);
AutoCFTypeRef<CFArrayRef> tags(::CGFontCopyTableTags(fontRef));
if (!tags) {
return false;
}
@@ -679,10 +679,10 @@ bool CTFontEntry::SupportsOpenTypeFeature(Script aScript,
CrashReporter::AutoRecordAnnotation autoFontName(
CrashReporter::Annotation::FontName, FamilyName());
AutoCFRelease<CTFontRef> ctFont =
CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
AutoCFTypeRef<CTFontRef> ctFont(
CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr));
if (ctFont) {
AutoCFRelease<CFArrayRef> features = CTFontCopyFeatures(ctFont);
AutoCFTypeRef<CFArrayRef> features(CTFontCopyFeatures(ctFont));
if (features) {
mHasAATSmallCaps = CheckForAATSmallCaps(features);
}
@@ -700,14 +700,14 @@ void CTFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
static CTFontDescriptorRef CreateDescriptorForFamily(
const nsACString& aFamilyName, bool aNormalized) {
AutoCFRelease<CFStringRef> family = CreateCFStringForString(aFamilyName);
AutoCFTypeRef<CFStringRef> family(CreateCFStringForString(aFamilyName));
const void* values[] = {family};
const void* keys[] = {kCTFontFamilyNameAttribute};
AutoCFRelease<CFDictionaryRef> attributes = CFDictionaryCreate(
AutoCFTypeRef<CFDictionaryRef> attributes(CFDictionaryCreate(
kCFAllocatorDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
&kCFTypeDictionaryValueCallBacks));
// Not AutoCFRelease, because we might return it.
// Not AutoCFTypeRef, because we might return it.
CTFontDescriptorRef descriptor =
CTFontDescriptorCreateWithAttributes(attributes);
@@ -724,12 +724,12 @@ static CTFontDescriptorRef CreateDescriptorForFamily(
}
void CTFontFamily::LocalizedName(nsACString& aLocalizedName) {
AutoCFRelease<CTFontDescriptorRef> descriptor =
CreateDescriptorForFamily(mName, true);
AutoCFTypeRef<CTFontDescriptorRef> descriptor(
CreateDescriptorForFamily(mName, true));
if (descriptor) {
AutoCFRelease<CFStringRef> name =
AutoCFTypeRef<CFStringRef> name(
static_cast<CFStringRef>(CTFontDescriptorCopyLocalizedAttribute(
descriptor, kCTFontFamilyNameAttribute, nullptr));
descriptor, kCTFontFamilyNameAttribute, nullptr)));
if (name) {
nsAutoString localized;
GetStringForCFString(name, localized);
@@ -824,15 +824,15 @@ static inline FontStretch CoreTextWidthToCSSStretch(CGFloat aCTWidth) {
}
void CTFontFamily::AddFace(CTFontDescriptorRef aFace) {
AutoCFRelease<CFStringRef> psname =
(CFStringRef)CTFontDescriptorCopyAttribute(aFace, kCTFontNameAttribute);
AutoCFRelease<CFStringRef> facename =
AutoCFTypeRef<CFStringRef> psname(
(CFStringRef)CTFontDescriptorCopyAttribute(aFace, kCTFontNameAttribute));
AutoCFTypeRef<CFStringRef> facename(
(CFStringRef)CTFontDescriptorCopyAttribute(aFace,
kCTFontStyleNameAttribute);
kCTFontStyleNameAttribute));
AutoCFRelease<CFDictionaryRef> traitsDict =
AutoCFTypeRef<CFDictionaryRef> traitsDict(
(CFDictionaryRef)CTFontDescriptorCopyAttribute(aFace,
kCTFontTraitsAttribute);
kCTFontTraitsAttribute));
CFNumberRef weight =
(CFNumberRef)CFDictionaryGetValue(traitsDict, kCTFontWeightTrait);
CFNumberRef width =
@@ -921,7 +921,7 @@ void CTFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
MOZ_ASSERT(gfxPlatform::HasVariationFontSupport());
auto addToFamily = [&](CTFontRef aFont) MOZ_REQUIRES(mLock) {
AutoCFRelease<CFStringRef> psName = CTFontCopyPostScriptName(aFont);
AutoCFTypeRef<CFStringRef> psName(CTFontCopyPostScriptName(aFont));
nsAutoString nameUTF16;
nsAutoCString nameUTF8;
GetStringForCFString(psName, nameUTF16);
@@ -944,8 +944,8 @@ void CTFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
addToFamily(mForSystemFont);
// See if there is a corresponding italic face, and add it to the family.
AutoCFRelease<CTFontRef> italicFont = CTFontCreateCopyWithSymbolicTraits(
mForSystemFont, 0.0, nullptr, kCTFontTraitItalic, kCTFontTraitItalic);
AutoCFTypeRef<CTFontRef> italicFont(CTFontCreateCopyWithSymbolicTraits(
mForSystemFont, 0.0, nullptr, kCTFontTraitItalic, kCTFontTraitItalic));
if (italicFont != mForSystemFont) {
addToFamily(italicFont);
}
@@ -979,10 +979,10 @@ void CTFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
MOZ_POP_THREAD_SAFETY;
};
AutoCFRelease<CTFontDescriptorRef> descriptor =
CreateDescriptorForFamily(mName, false);
AutoCFRelease<CFArrayRef> faces =
CTFontDescriptorCreateMatchingFontDescriptors(descriptor, nullptr);
AutoCFTypeRef<CTFontDescriptorRef> descriptor(
CreateDescriptorForFamily(mName, false));
AutoCFTypeRef<CFArrayRef> faces(
CTFontDescriptorCreateMatchingFontDescriptors(descriptor, nullptr));
if (faces) {
Context context{this};
@@ -1070,21 +1070,21 @@ void CoreTextFontList::AddFamily(CFStringRef aFamily) {
/* static */
void CoreTextFontList::ActivateFontsFromDir(
const nsACString& aDir, nsTHashSet<nsCStringHashKey>* aLoadedFamilies) {
AutoCFRelease<CFURLRef> directory = CFURLCreateFromFileSystemRepresentation(
AutoCFTypeRef<CFURLRef> directory(CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault, (const UInt8*)nsPromiseFlatCString(aDir).get(),
aDir.Length(), true);
aDir.Length(), true));
if (!directory) {
return;
}
AutoCFRelease<CFURLEnumeratorRef> enumerator =
AutoCFTypeRef<CFURLEnumeratorRef> enumerator(
CFURLEnumeratorCreateForDirectoryURL(kCFAllocatorDefault, directory,
kCFURLEnumeratorDefaultBehavior,
nullptr);
nullptr));
if (!enumerator) {
return;
}
AutoCFRelease<CFMutableArrayRef> urls =
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
AutoCFTypeRef<CFMutableArrayRef> urls(
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
if (!urls) {
return;
}
@@ -1101,16 +1101,15 @@ void CoreTextFontList::ActivateFontsFromDir(
if (!aLoadedFamilies) {
continue;
}
AutoCFRelease<CFArrayRef> descriptors =
CTFontManagerCreateFontDescriptorsFromURL(url);
AutoCFTypeRef<CFArrayRef> descriptors(
CTFontManagerCreateFontDescriptorsFromURL(url));
if (!descriptors || !CFArrayGetCount(descriptors)) {
continue;
}
CTFontDescriptorRef desc =
(CTFontDescriptorRef)CFArrayGetValueAtIndex(descriptors, 0);
AutoCFRelease<CFStringRef> name =
(CFStringRef)CTFontDescriptorCopyAttribute(desc,
kCTFontFamilyNameAttribute);
AutoCFTypeRef<CFStringRef> name((CFStringRef)CTFontDescriptorCopyAttribute(
desc, kCTFontFamilyNameAttribute));
nsAutoCString key;
key.SetLength((CFStringGetLength(name) + 1) * 3);
if (CFStringGetCString(name, key.BeginWriting(), key.Length(),
@@ -1177,8 +1176,8 @@ nsresult CoreTextFontList::InitFontListForPlatform() {
// We're not a content process, so get the available fonts directly
// from Core Text.
AutoCFRelease<CFArrayRef> familyNames =
CTFontManagerCopyAvailableFontFamilyNames();
AutoCFTypeRef<CFArrayRef> familyNames(
CTFontManagerCopyAvailableFontFamilyNames());
for (CFIndex i = 0; i < CFArrayGetCount(familyNames); i++) {
CFStringRef familyName =
(CFStringRef)CFArrayGetValueAtIndex(familyNames, i);
@@ -1245,8 +1244,8 @@ void CoreTextFontList::InitSharedFontListForPlatform() {
firstTime = false;
}
AutoCFRelease<CFArrayRef> familyNames =
CTFontManagerCopyAvailableFontFamilyNames();
AutoCFTypeRef<CFArrayRef> familyNames(
CTFontManagerCopyAvailableFontFamilyNames());
nsTArray<fontlist::Family::InitData> families;
families.SetCapacity(CFArrayGetCount(familyNames)
#if USE_DEPRECATED_FONT_FAMILY_NAMES
@@ -1347,11 +1346,11 @@ gfxFontEntry* CoreTextFontList::PlatformGlobalFontFallback(
mDefaultFont = CTFontCreateWithName(CFSTR("LucidaGrande"), 12.f, NULL);
}
AutoCFRelease<CTFontRef> fallback =
CTFontCreateForString(mDefaultFont, str, CFRangeMake(0, length));
AutoCFTypeRef<CTFontRef> fallback(
CTFontCreateForString(mDefaultFont, str, CFRangeMake(0, length)));
if (fallback) {
AutoCFRelease<CFStringRef> familyNameRef = CTFontCopyFamilyName(fallback);
AutoCFTypeRef<CFStringRef> familyNameRef(CTFontCopyFamilyName(fallback));
if (familyNameRef &&
CFStringCompare(familyNameRef, CFSTR("LastResort"),
@@ -1432,13 +1431,13 @@ gfxFontEntry* CoreTextFontList::LookupLocalFont(
CrashReporter::AutoRecordAnnotation autoFontName(
CrashReporter::Annotation::FontName, aFontName);
AutoCFRelease<CFStringRef> faceName = CreateCFStringForString(aFontName);
AutoCFTypeRef<CFStringRef> faceName(CreateCFStringForString(aFontName));
if (!faceName) {
return nullptr;
}
// lookup face based on postscript or full name
AutoCFRelease<CGFontRef> fontRef = CGFontCreateWithFontName(faceName);
AutoCFTypeRef<CGFontRef> fontRef(CGFontCreateWithFontName(faceName));
if (!fontRef) {
return nullptr;
}
@@ -1449,12 +1448,12 @@ gfxFontEntry* CoreTextFontList::LookupLocalFont(
// is allowed to be used.
// CGFontRef doesn't offer a family-name API, so we go via a CTFontRef.
AutoCFRelease<CTFontRef> ctFont =
CTFontCreateWithGraphicsFont(fontRef, 0.0, nullptr, nullptr);
AutoCFTypeRef<CTFontRef> ctFont(
CTFontCreateWithGraphicsFont(fontRef, 0.0, nullptr, nullptr));
if (!ctFont) {
return nullptr;
}
AutoCFRelease<CFStringRef> name = CTFontCopyFamilyName(ctFont);
AutoCFTypeRef<CFStringRef> name(CTFontCopyFamilyName(ctFont));
// Convert the family name to a key suitable for font-list lookup (8-bit,
// lowercased).
nsAutoCString key;
@@ -1510,9 +1509,9 @@ gfxFontEntry* CoreTextFontList::MakePlatformFont(const nsACString& aFontName,
CrashReporter::AutoRecordAnnotation autoFontName(
CrashReporter::Annotation::FontName, aFontName);
AutoCFRelease<CGDataProviderRef> provider =
::CGDataProviderCreateWithData(nullptr, aFontData, aLength, &ReleaseData);
AutoCFRelease<CGFontRef> fontRef = ::CGFontCreateWithDataProvider(provider);
AutoCFTypeRef<CGDataProviderRef> provider(::CGDataProviderCreateWithData(
nullptr, aFontData, aLength, &ReleaseData));
AutoCFTypeRef<CGFontRef> fontRef(::CGFontCreateWithDataProvider(provider));
if (!fontRef) {
return nullptr;
}
@@ -1576,16 +1575,16 @@ void CTFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
RecursiveMutexAutoLock lock(mLock);
// family name ==> CTFontDescriptor
AutoCFRelease<CFStringRef> family = CreateCFStringForString(aFamilyName);
AutoCFTypeRef<CFStringRef> family(CreateCFStringForString(aFamilyName));
AutoCFRelease<CFMutableDictionaryRef> attr =
AutoCFTypeRef<CFMutableDictionaryRef> attr(
CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
&kCFTypeDictionaryValueCallBacks));
CFDictionaryAddValue(attr, kCTFontFamilyNameAttribute, family);
AutoCFRelease<CTFontDescriptorRef> fd =
CTFontDescriptorCreateWithAttributes(attr);
AutoCFRelease<CFArrayRef> matchingFonts =
CTFontDescriptorCreateMatchingFontDescriptors(fd, NULL);
AutoCFTypeRef<CTFontDescriptorRef> fd(
CTFontDescriptorCreateWithAttributes(attr));
AutoCFTypeRef<CFArrayRef> matchingFonts(
CTFontDescriptorCreateMatchingFontDescriptors(fd, NULL));
if (!matchingFonts) {
return;
}
@@ -1610,8 +1609,8 @@ void CTFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
}
prevFace = faceDesc;
AutoCFRelease<CTFontRef> fontRef =
CTFontCreateWithFontDescriptor(faceDesc, 0.0, nullptr);
AutoCFTypeRef<CTFontRef> fontRef(
CTFontCreateWithFontDescriptor(faceDesc, 0.0, nullptr));
if (!fontRef) {
NS_WARNING("failed to create a CTFontRef");
continue;
@@ -1619,9 +1618,9 @@ void CTFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
if (mLoadCmaps) {
// face name
AutoCFRelease<CFStringRef> faceName =
AutoCFTypeRef<CFStringRef> faceName(
(CFStringRef)CTFontDescriptorCopyAttribute(faceDesc,
kCTFontNameAttribute);
kCTFontNameAttribute));
AutoTArray<UniChar, 1024> buffer;
CFIndex len = CFStringGetLength(faceName);
@@ -1633,8 +1632,8 @@ void CTFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
// load the cmap data
FontFaceData fontData;
AutoCFRelease<CFDataRef> cmapTable = CTFontCopyTable(
fontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions);
AutoCFTypeRef<CFDataRef> cmapTable(CTFontCopyTable(
fontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions));
if (cmapTable) {
const uint8_t* cmapData = (const uint8_t*)CFDataGetBytePtr(cmapTable);
@@ -1655,8 +1654,8 @@ void CTFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
}
if (mLoadOtherNames && hasOtherFamilyNames) {
AutoCFRelease<CFDataRef> nameTable = CTFontCopyTable(
fontRef, kCTFontTableName, kCTFontTableOptionNoOptions);
AutoCFTypeRef<CFDataRef> nameTable(CTFontCopyTable(
fontRef, kCTFontTableName, kCTFontTableOptionNoOptions));
if (nameTable) {
const char* nameData = (const char*)CFDataGetBytePtr(nameTable);
@@ -1702,15 +1701,14 @@ gfxFontEntry* CoreTextFontList::CreateFontEntry(
void CoreTextFontList::AddFaceInitData(
CTFontDescriptorRef aFontDesc, nsTArray<fontlist::Face::InitData>& aFaces,
bool aLoadCmaps) {
AutoCFRelease<CFStringRef> psname =
AutoCFTypeRef<CFStringRef> psname((CFStringRef)CTFontDescriptorCopyAttribute(
aFontDesc, kCTFontNameAttribute));
AutoCFTypeRef<CFStringRef> facename(
(CFStringRef)CTFontDescriptorCopyAttribute(aFontDesc,
kCTFontNameAttribute);
AutoCFRelease<CFStringRef> facename =
(CFStringRef)CTFontDescriptorCopyAttribute(aFontDesc,
kCTFontStyleNameAttribute);
AutoCFRelease<CFDictionaryRef> traitsDict =
kCTFontStyleNameAttribute));
AutoCFTypeRef<CFDictionaryRef> traitsDict(
(CFDictionaryRef)CTFontDescriptorCopyAttribute(aFontDesc,
kCTFontTraitsAttribute);
kCTFontTraitsAttribute));
CFNumberRef weight =
(CFNumberRef)CFDictionaryGetValue(traitsDict, kCTFontWeightTrait);
@@ -1752,11 +1750,11 @@ void CoreTextFontList::AddFaceInitData(
RefPtr<gfxCharacterMap> charmap;
if (aLoadCmaps) {
AutoCFRelease<CGFontRef> font =
CGFontCreateWithFontName(CFStringRef(psname));
AutoCFTypeRef<CGFontRef> font(
CGFontCreateWithFontName(CFStringRef(psname)));
if (font) {
uint32_t kCMAP = TRUETYPE_TAG('c', 'm', 'a', 'p');
AutoCFRelease<CFDataRef> data = CGFontCopyTableForTag(font, kCMAP);
AutoCFTypeRef<CFDataRef> data(CGFontCopyTableForTag(font, kCMAP));
if (data) {
uint32_t offset;
charmap = new gfxCharacterMap();
@@ -1808,10 +1806,10 @@ void CoreTextFontList::GetFacesInitDataForFamily(
context->mLoadCmaps);
};
AutoCFRelease<CTFontDescriptorRef> descriptor =
CreateDescriptorForFamily(name, false);
AutoCFRelease<CFArrayRef> faces =
CTFontDescriptorCreateMatchingFontDescriptors(descriptor, nullptr);
AutoCFTypeRef<CTFontDescriptorRef> descriptor(
CreateDescriptorForFamily(name, false));
AutoCFTypeRef<CFArrayRef> faces(
CTFontDescriptorCreateMatchingFontDescriptors(descriptor, nullptr));
if (faces) {
Context context{aFaces, aLoadCmaps};
@@ -1869,14 +1867,14 @@ void CoreTextFontList::ReadFaceNamesForFamily(
}
static CFStringRef CopyRealFamilyName(CTFontRef aFont) {
AutoCFRelease<CFStringRef> psName = CTFontCopyPostScriptName(aFont);
AutoCFRelease<CGFontRef> cgFont =
CGFontCreateWithFontName(CFStringRef(psName));
AutoCFTypeRef<CFStringRef> psName(CTFontCopyPostScriptName(aFont));
AutoCFTypeRef<CGFontRef> cgFont(
CGFontCreateWithFontName(CFStringRef(psName)));
if (!cgFont) {
return CTFontCopyFamilyName(aFont);
}
AutoCFRelease<CTFontRef> ctFont =
CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
AutoCFTypeRef<CTFontRef> ctFont(
CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr));
if (!ctFont) {
return CTFontCopyFamilyName(aFont);
}
@@ -1885,9 +1883,9 @@ static CFStringRef CopyRealFamilyName(CTFontRef aFont) {
void CoreTextFontList::InitSystemFontNames() {
// text font family
AutoCFRelease<CTFontRef> font = CTFontCreateUIFontForLanguage(
kCTFontUIFontSystem, 0.0, nullptr); // TODO: language
AutoCFRelease<CFStringRef> name = CopyRealFamilyName(font);
AutoCFTypeRef<CTFontRef> font(CTFontCreateUIFontForLanguage(
kCTFontUIFontSystem, 0.0, nullptr)); // TODO: language
AutoCFTypeRef<CFStringRef> name(CopyRealFamilyName(font));
nsAutoString familyName;
GetStringForCFString(name, familyName);
@@ -1908,9 +1906,9 @@ void CoreTextFontList::InitSystemFontNames() {
FontFamily CoreTextFontList::GetDefaultFontForPlatform(
nsPresContext* aPresContext, const gfxFontStyle* aStyle,
nsAtom* aLanguage) {
AutoCFRelease<CTFontRef> font = CTFontCreateUIFontForLanguage(
kCTFontUIFontUser, 0.0, nullptr); // TODO: language
AutoCFRelease<CFStringRef> name = CTFontCopyFamilyName(font);
AutoCFTypeRef<CTFontRef> font(CTFontCreateUIFontForLanguage(
kCTFontUIFontUser, 0.0, nullptr)); // TODO: language
AutoCFTypeRef<CFStringRef> name(CTFontCopyFamilyName(font));
nsAutoString familyName;
GetStringForCFString(name, familyName);

View File

@@ -221,8 +221,8 @@ void gfxMacFont::InitMetrics() {
// return the true value for OpenType/CFF fonts (it normalizes to 1000,
// which then leads to metrics errors when we read the 'hmtx' table to
// get glyph advances for HarfBuzz, see bug 580863)
AutoCFRelease<CFDataRef> headData =
::CGFontCopyTableForTag(mCGFont, TRUETYPE_TAG('h', 'e', 'a', 'd'));
AutoCFTypeRef<CFDataRef> headData(
::CGFontCopyTableForTag(mCGFont, TRUETYPE_TAG('h', 'e', 'a', 'd')));
if (headData) {
if (size_t(::CFDataGetLength(headData)) >= sizeof(HeadTable)) {
const HeadTable* head =
@@ -278,8 +278,8 @@ void gfxMacFont::InitMetrics() {
mMetrics.capHeight = ::CGFontGetCapHeight(mCGFont) * cgConvFactor;
}
AutoCFRelease<CFDataRef> cmap =
::CGFontCopyTableForTag(mCGFont, TRUETYPE_TAG('c', 'm', 'a', 'p'));
AutoCFTypeRef<CFDataRef> cmap(
::CGFontCopyTableForTag(mCGFont, TRUETYPE_TAG('c', 'm', 'a', 'p')));
uint32_t glyphID;
mMetrics.zeroWidth = GetCharWidth(cmap, '0', &glyphID, cgConvFactor);
@@ -505,8 +505,8 @@ bool gfxMacFont::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) {
// for sfnts, including ALL downloadable fonts, we prefer to use
// InitMetricsFromSfntTables and avoid platform APIs.
void gfxMacFont::InitMetricsFromPlatform() {
AutoCFRelease<CTFontRef> ctFont =
::CTFontCreateWithGraphicsFont(mCGFont, mAdjustedSize, nullptr, nullptr);
AutoCFTypeRef<CTFontRef> ctFont(
::CTFontCreateWithGraphicsFont(mCGFont, mAdjustedSize, nullptr, nullptr));
if (!ctFont) {
return;
}

View File

@@ -1344,8 +1344,8 @@ nsresult nsCocoaUtils::GetScreenCapturePermissionState(
// names if the calling application has been authorized to record the
// screen. We use the window name, window level, and owning PID as
// heuristics to determine if we have screen recording permission.
AutoCFRelease<CFArrayRef> windowArray =
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID);
AutoCFTypeRef<CFArrayRef> windowArray(
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
if (!windowArray) {
LOG("GetScreenCapturePermissionState() ERROR: got NULL window info list");
return NS_ERROR_UNEXPECTED;
@@ -1540,8 +1540,8 @@ void nsCocoaUtils::ResolveAudioCapturePromises(bool aGranted) {
//
nsresult nsCocoaUtils::MaybeRequestScreenCapturePermission() {
LOG("MaybeRequestScreenCapturePermission()");
AutoCFRelease<CGImageRef> image =
CGDisplayCreateImageForRect(kCGDirectMainDisplay, CGRectMake(0, 0, 1, 1));
AutoCFTypeRef<CGImageRef> image(CGDisplayCreateImageForRect(
kCGDirectMainDisplay, CGRectMake(0, 0, 1, 1)));
return NS_OK;
}

View File

@@ -121,12 +121,12 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIPrintSettings* aPS,
destination == kPMDestinationPreview) {
mPrintViaSkPDF = true;
} else if (destination == kPMDestinationFile) {
AutoCFRelease<CFURLRef> destURL(nullptr);
AutoCFTypeRef<CFURLRef> destURL(nullptr);
status = ::PMSessionCopyDestinationLocation(
mPrintSession, mPMPrintSettings, destURL.receive());
mPrintSession, mPMPrintSettings, destURL.Receive());
if (status == noErr) {
AutoCFRelease<CFStringRef> destPathRef =
CFURLCopyFileSystemPath(destURL, kCFURLPOSIXPathStyle);
AutoCFTypeRef<CFStringRef> destPathRef(
CFURLCopyFileSystemPath(destURL, kCFURLPOSIXPathStyle));
NSString* destPath = (NSString*)CFStringRef(destPathRef);
NSString* destPathExt = [destPath pathExtension];
if ([destPathExt isEqualToString:@"pdf"]) {
@@ -195,11 +195,11 @@ nsresult nsDeviceContextSpecX::DoEndDocument() {
if (!tmpPDFFile) {
return NS_ERROR_FAILURE;
}
AutoCFRelease<CFURLRef> pdfURL(nullptr);
AutoCFTypeRef<CFURLRef> pdfURL(nullptr);
// Note that the caller is responsible to release pdfURL according to
// nsILocalFileMac.idl, even though we didn't follow the Core Foundation
// naming conventions here (the method should've been called CopyCFURL).
nsresult rv = tmpPDFFile->GetCFURL(pdfURL.receive());
nsresult rv = tmpPDFFile->GetCFURL(pdfURL.Receive());
NS_ENSURE_SUCCESS(rv, rv);
PMDestinationType destination;
@@ -220,24 +220,24 @@ nsresult nsDeviceContextSpecX::DoEndDocument() {
}
case kPMDestinationPreview: {
// XXXjwatt Or should we use CocoaFileUtils::RevealFileInFinder(pdfURL);
AutoCFRelease<CFStringRef> pdfPath =
CFURLCopyFileSystemPath(pdfURL, kCFURLPOSIXPathStyle);
AutoCFTypeRef<CFStringRef> pdfPath(
CFURLCopyFileSystemPath(pdfURL, kCFURLPOSIXPathStyle));
NSString* path = (NSString*)CFStringRef(pdfPath);
NSWorkspace* ws = [NSWorkspace sharedWorkspace];
[ws openFile:path];
break;
}
case kPMDestinationFile: {
AutoCFRelease<CFURLRef> destURL(nullptr);
AutoCFTypeRef<CFURLRef> destURL(nullptr);
status = ::PMSessionCopyDestinationLocation(
mPrintSession, mPMPrintSettings, destURL.receive());
mPrintSession, mPMPrintSettings, destURL.Receive());
if (status == noErr) {
AutoCFRelease<CFStringRef> sourcePathRef =
CFURLCopyFileSystemPath(pdfURL, kCFURLPOSIXPathStyle);
AutoCFTypeRef<CFStringRef> sourcePathRef(
CFURLCopyFileSystemPath(pdfURL, kCFURLPOSIXPathStyle));
NSString* sourcePath = (NSString*)CFStringRef(sourcePathRef);
# ifdef DEBUG
AutoCFRelease<CFStringRef> destPathRef =
CFURLCopyFileSystemPath(destURL, kCFURLPOSIXPathStyle);
AutoCFTypeRef<CFStringRef> destPathRef(
CFURLCopyFileSystemPath(destURL, kCFURLPOSIXPathStyle));
NSString* destPath = (NSString*)CFStringRef(destPathRef);
NSString* destPathExt = [destPath pathExtension];
MOZ_ASSERT([destPathExt isEqualToString:@"pdf"],