Bug 1826412: Rip out all the ugly and move it to nsIGfxInfo r=jfkthame,fluent-reviewers,flod

This also adds debug information to about:support

Differential Revision: https://phabricator.services.mozilla.com/D200388
This commit is contained in:
Tom Ritter 2024-02-05 19:30:40 +00:00
Родитель a1ff4822f8
Коммит 41e2755e68
9 изменённых файлов: 232 добавлений и 78 удалений

Просмотреть файл

@ -144,6 +144,15 @@ class MockGfxInfo final : public nsIGfxInfo {
JS::MutableHandle<JS::Value>) override { JS::MutableHandle<JS::Value>) override {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHOD GetFontVisibilityDetermination(
nsIGfxInfo::FontVisibilityDeviceDetermination*
aFontVisibilityDetermination) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetFontVisibilityDeterminationStr(
nsAString& aFontVisibilityDeterminationStr) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override { NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }

Просмотреть файл

@ -36,6 +36,8 @@
#include "harfbuzz/hb-ot.h" // for name ID constants #include "harfbuzz/hb-ot.h" // for name ID constants
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsIGfxInfo.h"
#include "mozilla/Components.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
@ -1265,87 +1267,30 @@ void gfxFT2FontList::FindFontsInOmnijar(FontNameCache* aCache) {
} }
} }
static bool product_is_chromebook(nsCString product) { using Device = nsIGfxInfo::FontVisibilityDeviceDetermination;
return product == "asuka" || product == "asurada" || product == "atlas" ||
product == "auron" || product == "banjo" || product == "banon" ||
product == "bob" || product == "brask" || product == "brya" ||
product == "buddy" || product == "butterfly" || product == "candy" ||
product == "caroline" || product == "cave" || product == "celes" ||
product == "chell" || product == "cherry" || product == "clapper" ||
product == "coral" || product == "corsola" || product == "cyan" ||
product == "daisy" || product == "dedede" || product == "drallion" ||
product == "edgar" || product == "elm" || product == "enguarde" ||
product == "eve" || product == "expresso" || product == "falco" ||
product == "fizz" || product == "gandof" || product == "glimmer" ||
product == "gnawty" || product == "grunt" || product == "guado" ||
product == "guybrush" || product == "hana" || product == "hatch" ||
product == "heli" || product == "jacuzzi" || product == "kalista" ||
product == "kefka" || product == "kevin" || product == "kip" ||
product == "kukui" || product == "lars" || product == "leon" ||
product == "link" || product == "lulu" || product == "lumpy" ||
product == "mccloud" || product == "monroe" || product == "nami" ||
product == "nautilus" || product == "ninja" || product == "nissa" ||
product == "nocturne" || product == "nyan" || product == "octopus" ||
product == "orco" || product == "panther" || product == "parrot" ||
product == "peach" || product == "peppy" || product == "puff" ||
product == "pyro" || product == "quawks" || product == "rammus" ||
product == "reef" || product == "reks" || product == "relm" ||
product == "rikku" || product == "samus" || product == "sand" ||
product == "sarien" || product == "scarlet" || product == "sentry" ||
product == "setzer" || product == "skyrim" || product == "snappy" ||
product == "soraka" || product == "squawks" || product == "staryu" ||
product == "stout" || product == "strongbad" || product == "stumpy" ||
product == "sumo" || product == "swanky" || product == "terra" ||
product == "tidus" || product == "tricky" || product == "trogdor" ||
product == "ultima" || product == "veyron" || product == "volteer" ||
product == "winky" || product == "wizpig" || product == "wolf" ||
product == "x86" || product == "zako" || product == "zork";
}
FontVisibility gfxFT2FontList::GetVisibilityForFamily( FontVisibility gfxFT2FontList::GetVisibilityForFamily(
const nsACString& aName) const { const nsACString& aName) const {
static auto android_release_version = static Device fontVisibilityDevice = Device::Unassigned;
atoi(java::sdk::Build::VERSION::RELEASE()->ToCString().get()); if (fontVisibilityDevice == Device::Unassigned) {
if (android_release_version < 4 || android_release_version > 20) { nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
// Something is screwy, oh well. NS_ENSURE_SUCCESS(
gfxInfo->GetFontVisibilityDetermination(&fontVisibilityDevice),
FontVisibility::Unknown);
}
if (fontVisibilityDevice == Device::Android_Unknown_Release_Version ||
fontVisibilityDevice == Device::Android_Unknown_Peloton ||
fontVisibilityDevice == Device::Android_Unknown_vbox ||
fontVisibilityDevice == Device::Android_Unknown_mitv ||
fontVisibilityDevice == Device::Android_Chromebook ||
fontVisibilityDevice == Device::Android_Amazon) {
return FontVisibility::Unknown; return FontVisibility::Unknown;
} }
static auto android_manufacturer = // Sanity Check
java::sdk::Build::MANUFACTURER()->ToCString(); if (fontVisibilityDevice != Device::Android_sub_9 &&
nsContentUtils::ASCIIToLower(android_manufacturer); fontVisibilityDevice != Device::Android_9_11 &&
fontVisibilityDevice != Device::Android_12_plus) {
static auto android_brand = java::sdk::Build::BRAND()->ToCString();
nsContentUtils::ASCIIToLower(android_brand);
static auto android_model = java::sdk::Build::MODEL()->ToCString();
nsContentUtils::ASCIIToLower(android_model);
static auto android_product = java::sdk::Build::PRODUCT()->ToCString();
nsContentUtils::ASCIIToLower(android_product);
static auto android_product_is_chromebook =
product_is_chromebook(android_product);
if (android_manufacturer == "google" && android_model == android_product &&
android_product_is_chromebook) {
// Chromebook font set coming later
return FontVisibility::Unknown;
}
if (android_brand == "amazon") {
// Amazon Fire font set coming later
return FontVisibility::Unknown;
}
if (android_brand == "peloton") {
// We don't know how to categorize fonts on this system
return FontVisibility::Unknown;
}
if (android_product == "vbox86p") {
// We can't categorize fonts when running in an emulator on a Desktop
return FontVisibility::Unknown;
}
if (android_model.Find("mitv"_ns) != kNotFound && android_brand == "xiaomi") {
// We don't know how to categorize fonts on this system
return FontVisibility::Unknown; return FontVisibility::Unknown;
} }
@ -1353,7 +1298,7 @@ FontVisibility gfxFT2FontList::GetVisibilityForFamily(
return FontVisibility::Base; return FontVisibility::Base;
} }
if (android_release_version <= 8) { if (fontVisibilityDevice == Device::Android_sub_9) {
if (FamilyInList(aName, kBaseFonts_Android5_8)) { if (FamilyInList(aName, kBaseFonts_Android5_8)) {
return FontVisibility::Base; return FontVisibility::Base;
} }
@ -1362,7 +1307,7 @@ FontVisibility gfxFT2FontList::GetVisibilityForFamily(
return FontVisibility::Base; return FontVisibility::Base;
} }
if (android_release_version <= 11) { if (fontVisibilityDevice == Device::Android_9_11) {
if (FamilyInList(aName, kBaseFonts_Android9_11)) { if (FamilyInList(aName, kBaseFonts_Android9_11)) {
return FontVisibility::Base; return FontVisibility::Base;
} }

Просмотреть файл

@ -714,6 +714,9 @@ var snapshotFormatters = {
compositor = "BasicLayers (" + noOMTCString + ")"; compositor = "BasicLayers (" + noOMTCString + ")";
} }
addRow("features", "compositing", [new Text(compositor)]); addRow("features", "compositing", [new Text(compositor)]);
addRow("features", "supportFontDetermination", [
new Text(data.fontDetermination),
]);
delete data.windowLayerManagerRemote; delete data.windowLayerManagerRemote;
delete data.windowLayerManagerType; delete data.windowLayerManagerType;
delete data.numTotalWindows; delete data.numTotalWindows;

Просмотреть файл

@ -291,6 +291,7 @@ try-newer-driver = Blocked for your graphics driver version. Try updating your g
clear-type-parameters = ClearType Parameters clear-type-parameters = ClearType Parameters
compositing = Compositing compositing = Compositing
support-font-determination = Font Visibility Debug Info
hardware-h264 = Hardware H264 Decoding hardware-h264 = Hardware H264 Decoding
main-thread-no-omtc = main thread, no OMTC main-thread-no-omtc = main thread, no OMTC
yes = Yes yes = Yes

Просмотреть файл

@ -658,6 +658,7 @@ var dataProviders = {
cleartypeParameters: "clearTypeParameters", cleartypeParameters: "clearTypeParameters",
TargetFrameRate: "targetFrameRate", TargetFrameRate: "targetFrameRate",
windowProtocol: null, windowProtocol: null,
fontVisibilityDeterminationStr: "fontDetermination",
}; };
for (let prop in gfxInfoProps) { for (let prop in gfxInfoProps) {

Просмотреть файл

@ -785,6 +785,9 @@ const SNAPSHOT_SCHEMA = {
desktopEnvironment: { desktopEnvironment: {
type: "string", type: "string",
}, },
fontDetermination: {
type: "string",
},
}, },
}, },
media: { media: {

Просмотреть файл

@ -26,6 +26,7 @@
#include "nsTArray.h" #include "nsTArray.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
#include "nsIXULAppInfo.h" #include "nsIXULAppInfo.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_gfx.h" #include "mozilla/StaticPrefs_gfx.h"
@ -43,6 +44,11 @@
#include "gfxConfig.h" #include "gfxConfig.h"
#include "DriverCrashGuard.h" #include "DriverCrashGuard.h"
#ifdef MOZ_WIDGET_ANDROID
# include <set>
# include "AndroidBuild.h"
#endif
using namespace mozilla::widget; using namespace mozilla::widget;
using namespace mozilla; using namespace mozilla;
using mozilla::MutexAutoLock; using mozilla::MutexAutoLock;
@ -1883,6 +1889,158 @@ GfxInfoBase::GetIsHeadless(bool* aIsHeadless) {
return NS_OK; return NS_OK;
} }
#if defined(MOZ_WIDGET_ANDROID)
struct CharArrayComparator {
bool operator()(const char* lhs, const char* rhs) const {
return strcmp(lhs, rhs) < 0;
}
};
const char* chromebookProductList[] = {
"asuka", "asurada", "atlas", "auron", "banjo", "banon",
"bob", "brask", "brya", "buddy", "butterfly", "candy",
"caroline", "cave", "celes", "chell", "cherry", "clapper",
"coral", "corsola", "cyan", "daisy", "dedede", "drallion",
"edgar", "elm", "enguarde", "eve", "expresso", "falco",
"fizz", "gandof", "glimmer", "gnawty", "grunt", "guado",
"guybrush", "hana", "hatch", "heli", "jacuzzi", "kalista",
"kefka", "kevin", "kip", "kukui", "lars", "leon",
"link", "lulu", "lumpy", "mccloud", "monroe", "nami",
"nautilus", "ninja", "nissa", "nocturne", "nyan", "octopus",
"orco", "panther", "parrot", "peach", "peppy", "puff",
"pyro", "quawks", "rammus", "reef", "reks", "relm",
"rikku", "samus", "sand", "sarien", "scarlet", "sentry",
"setzer", "skyrim", "snappy", "soraka", "squawks", "staryu",
"stout", "strongbad", "stumpy", "sumo", "swanky", "terra",
"tidus", "tricky", "trogdor", "ultima", "veyron", "volteer",
"winky", "wizpig", "wolf", "x86", "zako", "zork"};
bool ProductIsChromebook(nsCString product) {
size_t result;
return BinarySearchIf(
chromebookProductList, 0, ArrayLength(chromebookProductList),
[&](const char* const aValue) -> int {
return strcmp(product.get(), aValue);
},
&result);
}
#endif
using Device = nsIGfxInfo::FontVisibilityDeviceDetermination;
std::pair<Device, nsString> GfxInfoBase::GetFontVisibilityDeterminationPair() {
static std::pair<Device, nsString> ret = {Device::Unassigned, u""_ns};
if (ret.first != Device::Unassigned) {
return ret;
}
#if defined(MOZ_WIDGET_ANDROID)
auto androidReleaseVersion = strtol(
java::sdk::Build::VERSION::RELEASE()->ToCString().get(), nullptr, 10);
auto androidManufacturer = java::sdk::Build::MANUFACTURER()->ToCString();
nsContentUtils::ASCIIToLower(androidManufacturer);
auto androidBrand = java::sdk::Build::BRAND()->ToCString();
nsContentUtils::ASCIIToLower(androidBrand);
auto androidModel = java::sdk::Build::MODEL()->ToCString();
nsContentUtils::ASCIIToLower(androidModel);
auto androidProduct = java::sdk::Build::PRODUCT()->ToCString();
nsContentUtils::ASCIIToLower(androidProduct);
auto androidProductIsChromebook = ProductIsChromebook(androidProduct);
if (androidReleaseVersion < 4 || androidReleaseVersion > 20) {
// Something is screwy, oh well.
ret.second.AppendASCII("Unknown Release Version - ");
ret.first = Device::Android_Unknown_Release_Version;
} else if (androidReleaseVersion <= 8) {
ret.second.AppendASCII("Android <9 - ");
ret.first = Device::Android_sub_9;
} else if (androidReleaseVersion <= 11) {
ret.second.AppendASCII("Android 9-11 - ");
ret.first = Device::Android_9_11;
} else if (androidReleaseVersion > 11) {
ret.second.AppendASCII("Android 12+ - ");
ret.first = Device::Android_12_plus;
} else {
MOZ_CRASH_UNSAFE_PRINTF(
"Somehow wound up in GetFontVisibilityDeterminationPair with a release "
"version of %li",
androidReleaseVersion);
}
if (androidManufacturer == "google" && androidModel == androidProduct &&
androidProductIsChromebook) {
// Chromebook font set coming later
ret.second.AppendASCII("Chromebook - ");
ret.first = Device::Android_Chromebook;
}
if (androidBrand == "amazon") {
// Amazon Fire font set coming later
ret.second.AppendASCII("Amazon - ");
ret.first = Device::Android_Amazon;
}
if (androidBrand == "peloton") {
// We don't know how to categorize fonts on this system
ret.second.AppendASCII("Peloton - ");
ret.first = Device::Android_Unknown_Peloton;
}
if (androidProduct == "vbox86p") {
ret.second.AppendASCII("vbox - ");
// We can't categorize fonts when running in an emulator on a Desktop
ret.first = Device::Android_Unknown_vbox;
}
if (androidModel.Find("mitv"_ns) != kNotFound && androidBrand == "xiaomi") {
// We don't know how to categorize fonts on this system
ret.second.AppendASCII("mitv - ");
ret.first = Device::Android_Unknown_mitv;
}
ret.second.AppendPrintf(
"release_version_str=%s, release_version=%li",
java::sdk::Build::VERSION::RELEASE()->ToCString().get(),
androidReleaseVersion);
ret.second.AppendPrintf(
", manufacturer=%s, brand=%s, model=%s, product=%s, chromebook=%s",
androidManufacturer.get(), androidBrand.get(), androidModel.get(),
androidProduct.get(), androidProductIsChromebook ? "yes" : "no");
#elif defined(XP_LINUX)
#elif defined(XP_MACOSX)
ret.first = Device::MacOS_Platform;
ret.second.AppendASCII("macOS Platform");
#elif defined(XP_WIN)
ret.first = Device::Windows_Platform;
ret.second.AppendASCII("Windows Platform");
#else
ret.first = Device::Unknown_Platform;
ret.second.AppendASCII("Unknown Platform");
#endif
return ret;
}
NS_IMETHODIMP
GfxInfoBase::GetFontVisibilityDetermination(
Device* aFontVisibilityDetermination) {
auto ret = GetFontVisibilityDeterminationPair();
*aFontVisibilityDetermination = ret.first;
return NS_OK;
}
NS_IMETHODIMP
GfxInfoBase::GetFontVisibilityDeterminationStr(
nsAString& aFontVisibilityDeterminationStr) {
auto ret = GetFontVisibilityDeterminationPair();
aFontVisibilityDeterminationStr.Assign(ret.second);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
GfxInfoBase::GetContentBackend(nsAString& aContentBackend) { GfxInfoBase::GetContentBackend(nsAString& aContentBackend) {
BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend(); BackendType backend = gfxPlatform::GetPlatform()->GetDefaultContentBackend();

Просмотреть файл

@ -64,6 +64,11 @@ class GfxInfoBase : public nsIGfxInfo,
NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override; NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
NS_IMETHOD GetActiveCrashGuards(JSContext*, NS_IMETHOD GetActiveCrashGuards(JSContext*,
JS::MutableHandle<JS::Value>) override; JS::MutableHandle<JS::Value>) override;
NS_IMETHOD GetFontVisibilityDetermination(
nsIGfxInfo::FontVisibilityDeviceDetermination*
aFontVisibilityDetermination) override;
NS_IMETHOD GetFontVisibilityDeterminationStr(
nsAString& aFontVisibilityDeterminationStr) override;
NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override; NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override;
NS_IMETHOD GetAzureCanvasBackend(nsAString& aBackend) override; NS_IMETHOD GetAzureCanvasBackend(nsAString& aBackend) override;
NS_IMETHOD GetAzureContentBackend(nsAString& aBackend) override; NS_IMETHOD GetAzureContentBackend(nsAString& aBackend) override;
@ -158,6 +163,9 @@ class GfxInfoBase : public nsIGfxInfo,
int32_t aFeature, nsACString& aFailureId, OperatingSystem os, int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
bool aForAllowing); bool aForAllowing);
std::pair<nsIGfxInfo::FontVisibilityDeviceDetermination, nsString>
GetFontVisibilityDeterminationPair();
bool IsFeatureAllowlisted(int32_t aFeature) const; bool IsFeatureAllowlisted(int32_t aFeature) const;
void EvaluateDownloadedBlocklist(nsTArray<GfxDriverInfo>& aDriverInfo); void EvaluateDownloadedBlocklist(nsTArray<GfxDriverInfo>& aDriverInfo);

Просмотреть файл

@ -39,6 +39,32 @@ interface nsIGfxInfo : nsISupports
// XXX: Switch to a list of devices, rather than explicitly numbering them. // XXX: Switch to a list of devices, rather than explicitly numbering them.
// Present on all platforms, but only useful on Android
cenum FontVisibilityDeviceDetermination : 8 {
Unassigned = 0,
Unknown_Platform = 1,
Windows_Platform = 2,
MacOS_Platform = 3,
Android_Unknown_Release_Version = 4,
Android_Unknown_Peloton = 5,
Android_Unknown_vbox = 6,
Android_Unknown_mitv = 7,
Android_Chromebook = 8,
Android_Amazon = 9,
Android_sub_9 = 10,
Android_9_11 = 11,
Android_12_plus = 12,
Linux_Unknown = 13,
Linux_Ubuntu_any = 14,
Linux_Ubuntu_20 = 15,
Linux_Ubuntu_22 = 16,
Linux_Fedora_any = 17,
Linux_Fedora_38 = 18,
Linux_Fedora_39 = 19
};
readonly attribute nsIGfxInfo_FontVisibilityDeviceDetermination fontVisibilityDetermination;
readonly attribute AString fontVisibilityDeterminationStr;
/** /**
* The name of the display adapter. * The name of the display adapter.
*/ */