Files
palemoon27/widget/cocoa/GfxInfo.mm
T
roytam1 faafb5fd9d import changes from `dev' branch of rmottola/Arctic-Fox:
- As suggested in PR 101, use OpenBSD assembler files. Update the NetBSD on them and use .S instead of .s, to indicate files to process (or preprocessor would fail on comments). (6a17dbacc3)
- Bug 1229769 - Expose Promise interface to WorkerDebugger #ifdef SPIDERMONKEY_PROMISE;r=bz (da9e838c23)
- Bug 1155969 - Make xpt.py flake8 compliant. r=ted (84f8eab5a3)
- Bug 977464 - Always relink XPT files for all changed XPIDL interfaces without requiring the IID to be revved; r=khuey (9b22512c41)
- Bug 977464 follow-up: Fix the indentation to use 4 spaces (bd68a8ebc3)
- Bug 1240053 - Consider the order of methods, their params, and constant important when comparing XPT interfaces to decide whether to relink XPT files; r=khuey (b9253dd183)
- Bug 1264377. Get rid of some unnecessary custom JSClass hook functions in xpconnect sandboxes and DOM simple globals. r=bholley (60950b416b)
- Bug 1258496 - Purge message manager cached scripts on 'message-manager-flush-caches' notification. r=smaug (028b229d02)
- Bug 1251298 - Null out |*idp| when necessary in DoInterfaceDescriptor. r=khuey. (dbdd15dae8)
- Bug 659625 - part1: implement Console::clear in dom/base/Console.cpp;r=baku (17c4b33789)
- Bug 659625 - part2: implement console.clear in devtools webconsole;r=bgrins (b72c6173ee)
- Bug 1248507 - p5. DecoderDoctorDiagnostics implementation - r=jya,bz (22f68130af)
- Bug 1248507 - p6. Minimal notification definition - r=bz (02f3eeb2f9)
- Bug 1248507 - p7. Notify decoder-doctor-notification listeners - r=jya,bz (2c2eb33388)
- Bug 1248507 - p8. FFMpeg checks: Console message - r=bz (50a993c143)
- Bug 1248507 - p9. FFMpeg checks: Notification definition - r=bz (0bcdcc090c)
- Bug 1248507 - p10. Detect and report when FFMpeg/Linux fails to load - r=jya (28137efda0)
- Bug 1190939: Decode VP9 4:4:4 properly. r=jya (98508bb48b)
- Bug 1232911 - [1.2] Allow to test for specific VPX MIME type version. r=cpearce (1b53e02981)
- Bug 1251887 - Add break to unintentional switch fallthrough in GfxInfoBase.cpp to fix -Wimplicit-fallthrough warning. r=milan (9969a7bec7)
- Bug 1232911 - [2.2] Add VPX decoding blocking support. r=snorp (fa860a9d4d)
- Bug 1249777: Added support for 10.11 in the blocklisting code as well. r=mstange (479f629083)
- Bug 1242084 - Fix GfxInfoBase nsStringBuffer leak. r=dvander (87b38ee72d)
- Bug 1222201: Only use container calculated dimensions. r=cpearce (693ebdf450)
- Bug 1190240 - Cannot compile WMFVideoMFTManager.cpp using Windows 10 SDK. r=cpearce (8ee2e315f5)
- Bug 1248496 - Enable D3D11 DXVA. r=ajones (a79df0baf2)
- Bug 1248496 - Show which DXVA API is being used in about:support. r=jya (1f6b1f0c8e)
- Bug 1257028 - Fallback to d3d9 decoding if d3d11 fails. r=cpearce (5ad7c159f1)
- Bug 1232045 - WebMDemuxer handles resolution changes. r=jya (18bdc79b1c)
- Bug 1243538: P1. Make MediaInfo::mImage an nsIntSize again and introduce a mImageRect member. r=mattwoodrow (a446cca01e)
- Bug 1243538: P2. Add convenience VideoInfo::ScaledImageRect. r=mattwoodrow (657e675b72)
- Bug 1243538: P3. Adjust libvpx decoder to allow different decoding size from metadata. r=mattwoodrow (50949ce02d)
- Bug 1243538: P4. Adjust ffvpx decoder to allow different decoding size from metadata. r=mattwoodrow (392c8939f5)
- Bug 1243538: P5. Adjust wmf decoder to allow different decoding size from metadata. r=cpearce (f50940564f)
- Bug 1239611 - Remove GonkNativeWindowClient r=nical (2c7ccb54a4)
- Bug 1170589 - Force decoder to use all allocated buffers. r=bwu (7e5c02e48a)
- Bug 1222923 - Enable MOZ_FMP4 on gonk L r=jolin (c04ad6ff55)
- Bug 1178214 - Return INIT_ERROR when video resolution exceeds hw codec capability. r=sotaro (bf3c45cde1)
- Bug 1147304 - Send codec specific data for MPEG4 codec type only. r=jya (ca48d110f4)
- Bug 1243538: P6. Adjust gonk decoder to allow different decoding size from metadata. r=alfredo (257e017762)
- Bug 1243538: [webm] P7. Let the decoder handle picture resizing. r=SingingTree (32dc4a5aac)
- Bug 1262727: [webm] Ensure first frame returned after seek is a keyframe. r=kinetik (f16140852a)
- Bug 1246536: [webm] Only use discard padding information on last packet. r=kinetik (0bac4f8855)
- Bug 1266013: Fix Firefox OS compile errors. r=gerald (f021717287)
- cleanup (390cdec6ee)
- Bug 1264991: Don't construct invalid channel configuration. r=gerald (661828e8b8)
- Bug 1265093: Fix CID 1358648. r=gerald (55468c1261)
- Bug 1262659 - Report HTTP Live Streaming playback requests. r=cpearce,bsmedberg (96b8cd2810)
- Bug 1265400 - Use unsigned long for AudioBuffer length and numberOfChannels; r=smaug (f74f27ea4e)
2024-05-18 23:12:44 +08:00

427 lines
12 KiB
Plaintext

/* -*- Mode: C++; tab-width: 2; 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 <OpenGL/OpenGL.h>
#include <OpenGL/CGLRenderers.h>
#include "mozilla/ArrayUtils.h"
#include "GfxInfo.h"
#include "nsUnicharUtils.h"
#include "nsCocoaFeatures.h"
#include "mozilla/Preferences.h"
#include <algorithm>
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
#import <Cocoa/Cocoa.h>
#if defined(MOZ_CRASHREPORTER)
#include "nsExceptionHandler.h"
#include "nsICrashReporter.h"
#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
#endif
using namespace mozilla;
using namespace mozilla::widget;
#ifdef DEBUG
NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
#endif
GfxInfo::GfxInfo()
{
}
static OperatingSystem
OSXVersionToOperatingSystem(uint32_t aOSXVersion)
{
if (nsCocoaFeatures::ExtractMajorVersion(aOSXVersion) == 10) {
switch (nsCocoaFeatures::ExtractMinorVersion(aOSXVersion)) {
case 6:
return DRIVER_OS_OS_X_10_6;
case 7:
return DRIVER_OS_OS_X_10_7;
case 8:
return DRIVER_OS_OS_X_10_8;
case 9:
return DRIVER_OS_OS_X_10_9;
case 10:
return DRIVER_OS_OS_X_10_10;
case 11:
return DRIVER_OS_OS_X_10_11;
}
}
return DRIVER_OS_UNKNOWN;
}
// The following three functions are derived from Chromium code
static CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort,
CFStringRef propertyName)
{
return IORegistryEntrySearchCFProperty(dspPort,
kIOServicePlane,
propertyName,
kCFAllocatorDefault,
kIORegistryIterateRecursively |
kIORegistryIterateParents);
}
static uint32_t IntValueOfCFData(CFDataRef d)
{
uint32_t value = 0;
if (d) {
const uint32_t *vp = reinterpret_cast<const uint32_t*>(CFDataGetBytePtr(d));
if (vp != NULL)
value = *vp;
}
return value;
}
void
GfxInfo::GetDeviceInfo()
{
io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay);
CFTypeRef vendor_id_ref = SearchPortForProperty(dsp_port, CFSTR("vendor-id"));
if (vendor_id_ref) {
mAdapterVendorID.AppendPrintf("0x%04x", IntValueOfCFData((CFDataRef)vendor_id_ref));
CFRelease(vendor_id_ref);
}
CFTypeRef device_id_ref = SearchPortForProperty(dsp_port, CFSTR("device-id"));
if (device_id_ref) {
mAdapterDeviceID.AppendPrintf("0x%04x", IntValueOfCFData((CFDataRef)device_id_ref));
CFRelease(device_id_ref);
}
}
nsresult
GfxInfo::Init()
{
nsresult rv = GfxInfoBase::Init();
// Calling CGLQueryRendererInfo causes us to switch to the discrete GPU
// even when we don't want to. We'll avoid doing so for now and just
// use the device ids.
GetDeviceInfo();
AddCrashReportAnnotations();
mOSXVersion = nsCocoaFeatures::OSXVersion();
return rv;
}
NS_IMETHODIMP
GfxInfo::GetD2DEnabled(bool *aEnabled)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
GfxInfo::GetDWriteEnabled(bool *aEnabled)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString DWriteVersion; */
NS_IMETHODIMP
GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString cleartypeParameters; */
NS_IMETHODIMP
GfxInfo::GetCleartypeParameters(nsAString & aCleartypeParams)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDescription; */
NS_IMETHODIMP
GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)
{
aAdapterDescription.AssignLiteral("");
return NS_OK;
}
/* readonly attribute DOMString adapterDescription2; */
NS_IMETHODIMP
GfxInfo::GetAdapterDescription2(nsAString & aAdapterDescription)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterRAM; */
NS_IMETHODIMP
GfxInfo::GetAdapterRAM(nsAString & aAdapterRAM)
{
aAdapterRAM = mAdapterRAMString;
return NS_OK;
}
/* readonly attribute DOMString adapterRAM2; */
NS_IMETHODIMP
GfxInfo::GetAdapterRAM2(nsAString & aAdapterRAM)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDriver; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriver(nsAString & aAdapterDriver)
{
aAdapterDriver.AssignLiteral("");
return NS_OK;
}
/* readonly attribute DOMString adapterDriver2; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriver2(nsAString & aAdapterDriver)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDriverVersion; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriverVersion(nsAString & aAdapterDriverVersion)
{
aAdapterDriverVersion.AssignLiteral("");
return NS_OK;
}
/* readonly attribute DOMString adapterDriverVersion2; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDriverDate; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriverDate(nsAString & aAdapterDriverDate)
{
aAdapterDriverDate.AssignLiteral("");
return NS_OK;
}
/* readonly attribute DOMString adapterDriverDate2; */
NS_IMETHODIMP
GfxInfo::GetAdapterDriverDate2(nsAString & aAdapterDriverDate)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterVendorID; */
NS_IMETHODIMP
GfxInfo::GetAdapterVendorID(nsAString & aAdapterVendorID)
{
aAdapterVendorID = mAdapterVendorID;
return NS_OK;
}
/* readonly attribute DOMString adapterVendorID2; */
NS_IMETHODIMP
GfxInfo::GetAdapterVendorID2(nsAString & aAdapterVendorID)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDeviceID; */
NS_IMETHODIMP
GfxInfo::GetAdapterDeviceID(nsAString & aAdapterDeviceID)
{
aAdapterDeviceID = mAdapterDeviceID;
return NS_OK;
}
/* readonly attribute DOMString adapterDeviceID2; */
NS_IMETHODIMP
GfxInfo::GetAdapterDeviceID2(nsAString & aAdapterDeviceID)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterSubsysID; */
NS_IMETHODIMP
GfxInfo::GetAdapterSubsysID(nsAString & aAdapterSubsysID)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterSubsysID2; */
NS_IMETHODIMP
GfxInfo::GetAdapterSubsysID2(nsAString & aAdapterSubsysID)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute boolean isGPU2Active; */
NS_IMETHODIMP
GfxInfo::GetIsGPU2Active(bool* aIsGPU2Active)
{
return NS_ERROR_FAILURE;
}
void
GfxInfo::AddCrashReportAnnotations()
{
#if defined(MOZ_CRASHREPORTER)
nsString deviceID, vendorID, driverVersion;
nsAutoCString narrowDeviceID, narrowVendorID, narrowDriverVersion;
GetAdapterDeviceID(deviceID);
CopyUTF16toUTF8(deviceID, narrowDeviceID);
GetAdapterVendorID(vendorID);
CopyUTF16toUTF8(vendorID, narrowVendorID);
GetAdapterDriverVersion(driverVersion);
CopyUTF16toUTF8(driverVersion, narrowDriverVersion);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterVendorID"),
narrowVendorID);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterDeviceID"),
narrowDeviceID);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterDriverVersion"),
narrowDriverVersion);
/* Add an App Note for now so that we get the data immediately. These
* can go away after we store the above in the socorro db */
nsAutoCString note;
/* AppendPrintf only supports 32 character strings, mrghh. */
note.Append("AdapterVendorID: ");
note.Append(narrowVendorID);
note.Append(", AdapterDeviceID: ");
note.Append(narrowDeviceID);
CrashReporter::AppendAppNotesToCrashReport(note);
#endif
}
// We don't support checking driver versions on Mac.
#define IMPLEMENT_MAC_DRIVER_BLOCKLIST(os, vendor, device, features, blockOn, ruleId) \
APPEND_TO_DRIVER_BLOCKLIST(os, vendor, device, features, blockOn, \
DRIVER_COMPARISON_IGNORED, V(0,0,0,0), ruleId, "")
const nsTArray<GfxDriverInfo>&
GfxInfo::GetGfxDriverInfo()
{
if (!mDriverInfo->Length()) {
IMPLEMENT_MAC_DRIVER_BLOCKLIST(DRIVER_OS_ALL,
(nsAString&) GfxDriverInfo::GetDeviceVendor(VendorATI), GfxDriverInfo::allDevices,
nsIGfxInfo::FEATURE_WEBGL_MSAA, nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION, "FEATURE_FAILURE_MAC_ATI_NO_MSAA");
IMPLEMENT_MAC_DRIVER_BLOCKLIST(DRIVER_OS_ALL,
(nsAString&) GfxDriverInfo::GetDeviceVendor(VendorATI), (GfxDeviceFamily*) GfxDriverInfo::GetDeviceFamily(RadeonX1000),
nsIGfxInfo::FEATURE_OPENGL_LAYERS, nsIGfxInfo::FEATURE_BLOCKED_DEVICE, "FEATURE_FAILURE_MAC_RADEONX1000_NO_TEXTURE2D");
IMPLEMENT_MAC_DRIVER_BLOCKLIST(DRIVER_OS_ALL,
(nsAString&) GfxDriverInfo::GetDeviceVendor(VendorNVIDIA), (GfxDeviceFamily*) GfxDriverInfo::GetDeviceFamily(Geforce7300GT),
nsIGfxInfo::FEATURE_WEBGL_OPENGL, nsIGfxInfo::FEATURE_BLOCKED_DEVICE, "FEATURE_FAILURE_MAC_7300_NO_WEBGL");
}
return *mDriverInfo;
}
nsresult
GfxInfo::GetFeatureStatusImpl(int32_t aFeature,
int32_t* aStatus,
nsAString& aSuggestedDriverVersion,
const nsTArray<GfxDriverInfo>& aDriverInfo,
nsACString& aFailureId,
OperatingSystem* aOS /* = nullptr */)
{
NS_ENSURE_ARG_POINTER(aStatus);
aSuggestedDriverVersion.SetIsVoid(true);
*aStatus = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
OperatingSystem os = OSXVersionToOperatingSystem(mOSXVersion);
if (aOS)
*aOS = os;
// Don't evaluate special cases when we're evaluating the downloaded blocklist.
if (!aDriverInfo.Length()) {
if (aFeature == nsIGfxInfo::FEATURE_WEBGL_MSAA) {
// Blacklist all ATI cards on OSX, except for
// 0x6760 and 0x9488
if (mAdapterVendorID.Equals(GfxDriverInfo::GetDeviceVendor(VendorATI), nsCaseInsensitiveStringComparator()) &&
(mAdapterDeviceID.LowerCaseEqualsLiteral("0x6760") ||
mAdapterDeviceID.LowerCaseEqualsLiteral("0x9488"))) {
*aStatus = nsIGfxInfo::FEATURE_STATUS_OK;
return NS_OK;
}
} else if (aFeature == nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION) {
// See bug 1249659
if (os > DRIVER_OS_OS_X_10_7) {
*aStatus = nsIGfxInfo::FEATURE_STATUS_OK;
} else {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
aFailureId = "FEATURE_FAILURE_CANVAS_OSX_VERSION";
}
return NS_OK;
}
}
return GfxInfoBase::GetFeatureStatusImpl(aFeature, aStatus, aSuggestedDriverVersion, aDriverInfo, aFailureId, &os);
}
nsresult
GfxInfo::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray)
{
// Getting the refresh rate is a little hard on OS X. We could use
// CVDisplayLinkGetNominalOutputVideoRefreshPeriod, but that's a little
// involved. Ideally we could query it from vsync. For now, we leave it out.
int32_t deviceCount = 0;
for (NSScreen* screen in [NSScreen screens]) {
NSRect rect = [screen frame];
JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value((int)rect.size.width));
JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value((int)rect.size.height));
JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
JS::Rooted<JS::Value> scale(aCx, JS::NumberValue(nsCocoaUtils::GetBackingScaleFactor(screen)));
JS_SetProperty(aCx, obj, "scale", scale);
JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
JS_SetElement(aCx, aOutArray, deviceCount++, element);
}
return NS_OK;
}
#ifdef DEBUG
// Implement nsIGfxInfoDebug
/* void spoofVendorID (in DOMString aVendorID); */
NS_IMETHODIMP GfxInfo::SpoofVendorID(const nsAString & aVendorID)
{
mAdapterVendorID = aVendorID;
return NS_OK;
}
/* void spoofDeviceID (in unsigned long aDeviceID); */
NS_IMETHODIMP GfxInfo::SpoofDeviceID(const nsAString & aDeviceID)
{
mAdapterDeviceID = aDeviceID;
return NS_OK;
}
/* void spoofDriverVersion (in DOMString aDriverVersion); */
NS_IMETHODIMP GfxInfo::SpoofDriverVersion(const nsAString & aDriverVersion)
{
mDriverVersion = aDriverVersion;
return NS_OK;
}
/* void spoofOSVersion (in unsigned long aVersion); */
NS_IMETHODIMP GfxInfo::SpoofOSVersion(uint32_t aVersion)
{
mOSXVersion = aVersion;
return NS_OK;
}
#endif