2013-01-18 00:45:11 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2006-02-01 02:35:38 +00:00
|
|
|
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
|
2014-11-10 21:41:40 +00:00
|
|
|
#include "cairo.h"
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
|
2006-02-01 02:35:38 +00:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
|
2006-06-10 00:21:05 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-11-22 03:35:40 +00:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2006-06-10 00:21:05 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2015-02-22 22:53:32 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2006-06-10 00:21:05 +00:00
|
|
|
|
2007-01-05 15:51:27 +00:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2008-10-01 03:01:53 +00:00
|
|
|
#include "plbase64.h"
|
2010-08-28 02:44:37 +00:00
|
|
|
#include "nsIXULRuntime.h"
|
2015-01-08 00:10:49 +00:00
|
|
|
#include "imgLoader.h"
|
2007-01-05 15:51:27 +00:00
|
|
|
|
2010-08-30 21:45:29 +00:00
|
|
|
#include "nsIGfxInfo.h"
|
2014-11-03 22:55:00 +00:00
|
|
|
#include "GfxDriverInfo.h"
|
2010-08-30 21:45:29 +00:00
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
#include "gfxGDIFontList.h"
|
2010-03-15 09:34:25 +00:00
|
|
|
#include "gfxGDIFont.h"
|
2011-06-18 09:04:30 +00:00
|
|
|
|
2013-11-21 22:07:57 +00:00
|
|
|
#include "mozilla/layers/CompositorParent.h" // for CompositorParent::IsInCompositorThread
|
2013-08-04 07:46:17 +00:00
|
|
|
#include "DeviceManagerD3D9.h"
|
2014-07-30 13:38:46 +00:00
|
|
|
#include "mozilla/layers/ReadbackManagerD3D11.h"
|
2013-08-04 07:46:17 +00:00
|
|
|
|
2013-12-14 20:40:55 +00:00
|
|
|
#include "WinUtils.h"
|
|
|
|
|
2010-02-27 16:05:54 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2010-02-26 06:36:07 +00:00
|
|
|
#include "gfxDWriteFontList.h"
|
|
|
|
#include "gfxDWriteFonts.h"
|
|
|
|
#include "gfxDWriteCommon.h"
|
|
|
|
#include <dwrite.h>
|
2009-01-23 06:24:29 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
#include "gfxTextRun.h"
|
2011-06-17 12:55:51 +00:00
|
|
|
#include "gfxUserFontSet.h"
|
2013-02-28 21:10:17 +00:00
|
|
|
#include "nsWindowsHelpers.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2011-06-17 12:55:51 +00:00
|
|
|
|
|
|
|
#include <string>
|
2011-06-15 10:22:57 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
#include "gfxD2DSurface.h"
|
2010-06-30 13:52:13 +00:00
|
|
|
|
2010-08-14 06:34:55 +00:00
|
|
|
#include <d3d10_1.h>
|
|
|
|
|
2011-06-24 17:41:18 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2010-06-30 13:52:13 +00:00
|
|
|
#include "nsMemory.h"
|
2011-06-17 12:55:51 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-01 14:27:09 +00:00
|
|
|
#include <d3d11.h>
|
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
#include <winternl.h>
|
2013-05-02 14:50:51 +00:00
|
|
|
#include "d3dkmtQueryStatistics.h"
|
2012-02-08 23:13:50 +00:00
|
|
|
|
2014-02-08 19:37:39 +00:00
|
|
|
#include "SurfaceCache.h"
|
2014-02-27 02:53:32 +00:00
|
|
|
#include "gfxPrefs.h"
|
2013-11-07 10:20:08 +00:00
|
|
|
|
2014-11-04 23:17:11 +00:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
|
|
|
|
2015-02-13 09:17:24 +00:00
|
|
|
#include "VsyncSource.h"
|
|
|
|
|
2011-06-17 12:55:51 +00:00
|
|
|
using namespace mozilla;
|
2013-12-14 20:40:55 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::widget;
|
2014-02-08 19:37:39 +00:00
|
|
|
using namespace mozilla::image;
|
2010-06-30 13:52:13 +00:00
|
|
|
|
2014-11-10 21:41:40 +00:00
|
|
|
DCFromDrawTarget::DCFromDrawTarget(DrawTarget& aDrawTarget)
|
|
|
|
{
|
|
|
|
mDC = nullptr;
|
|
|
|
if (aDrawTarget.GetBackendType() == BackendType::CAIRO) {
|
|
|
|
cairo_surface_t *surf = (cairo_surface_t*)
|
|
|
|
aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_SURFACE);
|
2014-11-17 21:41:41 +00:00
|
|
|
if (surf) {
|
|
|
|
cairo_surface_type_t surfaceType = cairo_surface_get_type(surf);
|
|
|
|
if (surfaceType == CAIRO_SURFACE_TYPE_WIN32 ||
|
|
|
|
surfaceType == CAIRO_SURFACE_TYPE_WIN32_PRINTING) {
|
|
|
|
mDC = cairo_win32_surface_get_dc(surf);
|
|
|
|
mNeedsRelease = false;
|
|
|
|
SaveDC(mDC);
|
|
|
|
cairo_t* ctx = (cairo_t*)
|
|
|
|
aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT);
|
|
|
|
cairo_scaled_font_t* scaled = cairo_get_scaled_font(ctx);
|
|
|
|
cairo_win32_scaled_font_select_font(scaled, mDC);
|
|
|
|
}
|
2014-11-10 21:41:40 +00:00
|
|
|
}
|
|
|
|
if (!mDC) {
|
|
|
|
mDC = GetDC(nullptr);
|
|
|
|
SetGraphicsMode(mDC, GM_ADVANCED);
|
|
|
|
mNeedsRelease = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 12:55:51 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
2010-06-30 13:52:13 +00:00
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
static const char *kFeatureLevelPref =
|
|
|
|
"gfx.direct3d.last_used_feature_level_idx";
|
|
|
|
static const int kSupportedFeatureLevels[] =
|
|
|
|
{ D3D10_FEATURE_LEVEL_10_1, D3D10_FEATURE_LEVEL_10_0,
|
|
|
|
D3D10_FEATURE_LEVEL_9_3 };
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class GfxD2DSurfaceReporter final : public nsIMemoryReporter
|
2013-01-18 00:45:11 +00:00
|
|
|
{
|
2014-07-17 20:47:19 +00:00
|
|
|
~GfxD2DSurfaceReporter() {}
|
|
|
|
|
2013-01-18 00:45:11 +00:00
|
|
|
public:
|
2013-12-08 06:09:10 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-01-18 00:45:11 +00:00
|
|
|
{
|
2013-12-08 06:09:10 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
int64_t amount = cairo_d2d_get_image_surface_cache_usage();
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
|
|
"gfx-d2d-surface-cache", KIND_OTHER, UNITS_BYTES, amount,
|
|
|
|
"Memory used by the Direct2D internal surface cache.");
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
cairo_device_t *device =
|
|
|
|
gfxWindowsPlatform::GetPlatform()->GetD2DDevice();
|
|
|
|
amount = device ? cairo_d2d_get_surface_vram_usage(device) : 0;
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
|
|
"gfx-d2d-surface-vram", KIND_OTHER, UNITS_BYTES, amount,
|
|
|
|
"Video memory used by D2D surfaces.");
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-01-18 00:45:11 +00:00
|
|
|
}
|
|
|
|
};
|
2010-06-30 13:52:13 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(GfxD2DSurfaceReporter, nsIMemoryReporter)
|
2013-12-08 06:09:10 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#endif
|
2009-07-08 23:34:02 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class GfxD2DVramReporter final : public nsIMemoryReporter
|
2012-06-20 21:41:16 +00:00
|
|
|
{
|
2014-07-15 01:49:53 +00:00
|
|
|
~GfxD2DVramReporter() {}
|
|
|
|
|
2013-01-18 00:45:11 +00:00
|
|
|
public:
|
2013-12-08 06:09:10 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2012-06-20 21:41:16 +00:00
|
|
|
|
2013-12-08 06:09:10 +00:00
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-01-18 00:45:11 +00:00
|
|
|
{
|
2013-12-08 06:09:10 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
|
|
"gfx-d2d-vram-draw-target", KIND_OTHER, UNITS_BYTES,
|
|
|
|
Factory::GetD2DVRAMUsageDrawTarget(),
|
|
|
|
"Video memory used by D2D DrawTargets.");
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
|
|
"gfx-d2d-vram-source-surface", KIND_OTHER, UNITS_BYTES,
|
|
|
|
Factory::GetD2DVRAMUsageSourceSurface(),
|
|
|
|
"Video memory used by D2D SourceSurfaces.");
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-01-18 00:45:11 +00:00
|
|
|
}
|
|
|
|
};
|
2012-06-20 21:41:16 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(GfxD2DVramReporter, nsIMemoryReporter)
|
2013-12-08 06:09:10 +00:00
|
|
|
|
2010-05-27 05:05:30 +00:00
|
|
|
#define GFX_USE_CLEARTYPE_ALWAYS "gfx.font_rendering.cleartype.always_use_for_content"
|
|
|
|
#define GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE "gfx.font_rendering.cleartype.use_for_downloadable_fonts"
|
|
|
|
|
2011-04-21 06:29:50 +00:00
|
|
|
#define GFX_CLEARTYPE_PARAMS "gfx.font_rendering.cleartype_params."
|
|
|
|
#define GFX_CLEARTYPE_PARAMS_GAMMA "gfx.font_rendering.cleartype_params.gamma"
|
|
|
|
#define GFX_CLEARTYPE_PARAMS_CONTRAST "gfx.font_rendering.cleartype_params.enhanced_contrast"
|
|
|
|
#define GFX_CLEARTYPE_PARAMS_LEVEL "gfx.font_rendering.cleartype_params.cleartype_level"
|
|
|
|
#define GFX_CLEARTYPE_PARAMS_STRUCTURE "gfx.font_rendering.cleartype_params.pixel_structure"
|
|
|
|
#define GFX_CLEARTYPE_PARAMS_MODE "gfx.font_rendering.cleartype_params.rendering_mode"
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class GPUAdapterReporter final : public nsIMemoryReporter
|
2013-11-06 03:58:20 +00:00
|
|
|
{
|
2012-02-08 23:13:50 +00:00
|
|
|
// Callers must Release the DXGIAdapter after use or risk mem-leak
|
2013-05-03 13:01:49 +00:00
|
|
|
static bool GetDXGIAdapter(IDXGIAdapter **DXGIAdapter)
|
2012-02-08 23:13:50 +00:00
|
|
|
{
|
|
|
|
ID3D10Device1 *D2D10Device;
|
|
|
|
IDXGIDevice *DXGIDevice;
|
|
|
|
bool result = false;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2014-11-27 09:58:41 +00:00
|
|
|
if ((D2D10Device = mozilla::gfx::Factory::GetDirect3D10Device())) {
|
2012-02-08 23:13:50 +00:00
|
|
|
if (D2D10Device->QueryInterface(__uuidof(IDXGIDevice), (void **)&DXGIDevice) == S_OK) {
|
|
|
|
result = (DXGIDevice->GetAdapter(DXGIAdapter) == S_OK);
|
|
|
|
DXGIDevice->Release();
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2014-07-15 20:41:50 +00:00
|
|
|
~GPUAdapterReporter() {}
|
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
public:
|
2013-12-08 05:39:47 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-05-02 14:50:51 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
NS_IMETHOD
|
2013-08-27 23:24:51 +00:00
|
|
|
CollectReports(nsIMemoryReporterCallback* aCb,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aClosure, bool aAnonymize)
|
2012-02-08 23:13:50 +00:00
|
|
|
{
|
|
|
|
HANDLE ProcessHandle = GetCurrentProcess();
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t dedicatedBytesUsed = 0;
|
|
|
|
int64_t sharedBytesUsed = 0;
|
|
|
|
int64_t committedBytesUsed = 0;
|
2012-02-08 23:13:50 +00:00
|
|
|
IDXGIAdapter *DXGIAdapter;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
HMODULE gdi32Handle;
|
2013-05-02 14:50:51 +00:00
|
|
|
PFND3DKMTQS queryD3DKMTStatistics;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
// GPU memory reporting is not available before Windows 7
|
2014-05-21 06:06:54 +00:00
|
|
|
if (!IsWin7OrLater())
|
2012-02-08 23:13:50 +00:00
|
|
|
return NS_OK;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2014-11-27 09:58:41 +00:00
|
|
|
if ((gdi32Handle = LoadLibrary(TEXT("gdi32.dll"))))
|
2013-05-02 14:50:51 +00:00
|
|
|
queryD3DKMTStatistics = (PFND3DKMTQS)GetProcAddress(gdi32Handle, "D3DKMTQueryStatistics");
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
if (queryD3DKMTStatistics && GetDXGIAdapter(&DXGIAdapter)) {
|
|
|
|
// Most of this block is understood thanks to wj32's work on Process Hacker
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
DXGI_ADAPTER_DESC adapterDesc;
|
2013-05-02 14:50:51 +00:00
|
|
|
D3DKMTQS queryStatistics;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
DXGIAdapter->GetDesc(&adapterDesc);
|
|
|
|
DXGIAdapter->Release();
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2013-05-02 14:50:51 +00:00
|
|
|
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
|
|
|
queryStatistics.Type = D3DKMTQS_PROCESS;
|
2012-02-08 23:13:50 +00:00
|
|
|
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
|
|
|
queryStatistics.hProcess = ProcessHandle;
|
|
|
|
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
2013-05-02 14:50:51 +00:00
|
|
|
committedBytesUsed = queryStatistics.QueryResult.ProcessInfo.SystemMemory.BytesAllocated;
|
2012-02-08 23:13:50 +00:00
|
|
|
}
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2013-05-02 14:50:51 +00:00
|
|
|
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
|
|
|
queryStatistics.Type = D3DKMTQS_ADAPTER;
|
2012-02-08 23:13:50 +00:00
|
|
|
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
|
|
|
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
|
|
|
ULONG i;
|
2013-05-02 14:50:51 +00:00
|
|
|
ULONG segmentCount = queryStatistics.QueryResult.AdapterInfo.NbSegments;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
for (i = 0; i < segmentCount; i++) {
|
2013-05-02 14:50:51 +00:00
|
|
|
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
|
|
|
queryStatistics.Type = D3DKMTQS_SEGMENT;
|
2012-02-08 23:13:50 +00:00
|
|
|
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
|
|
|
queryStatistics.QuerySegment.SegmentId = i;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
|
|
|
bool aperture;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
// SegmentInformation has a different definition in Win7 than later versions
|
2013-11-22 03:35:40 +00:00
|
|
|
if (!IsWin8OrLater())
|
2013-05-02 14:50:51 +00:00
|
|
|
aperture = queryStatistics.QueryResult.SegmentInfoWin7.Aperture;
|
2012-02-08 23:13:50 +00:00
|
|
|
else
|
2013-05-02 14:50:51 +00:00
|
|
|
aperture = queryStatistics.QueryResult.SegmentInfoWin8.Aperture;
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2013-05-02 14:50:51 +00:00
|
|
|
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
|
|
|
|
queryStatistics.Type = D3DKMTQS_PROCESS_SEGMENT;
|
2012-02-08 23:13:50 +00:00
|
|
|
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
|
|
|
|
queryStatistics.hProcess = ProcessHandle;
|
|
|
|
queryStatistics.QueryProcessSegment.SegmentId = i;
|
|
|
|
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
|
2014-04-27 01:36:00 +00:00
|
|
|
ULONGLONG bytesCommitted;
|
|
|
|
if (!IsWin8OrLater())
|
|
|
|
bytesCommitted = queryStatistics.QueryResult.ProcessSegmentInfo.Win7.BytesCommitted;
|
|
|
|
else
|
|
|
|
bytesCommitted = queryStatistics.QueryResult.ProcessSegmentInfo.Win8.BytesCommitted;
|
2012-02-08 23:13:50 +00:00
|
|
|
if (aperture)
|
2014-04-27 01:36:00 +00:00
|
|
|
sharedBytesUsed += bytesCommitted;
|
2012-02-08 23:13:50 +00:00
|
|
|
else
|
2014-04-27 01:36:00 +00:00
|
|
|
dedicatedBytesUsed += bytesCommitted;
|
2012-02-08 23:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
FreeLibrary(gdi32Handle);
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
nsresult rv; \
|
|
|
|
rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
|
2013-12-11 19:59:39 +00:00
|
|
|
KIND_OTHER, UNITS_BYTES, _amount, \
|
2012-03-04 23:26:30 +00:00
|
|
|
NS_LITERAL_CSTRING(_desc), aClosure); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
REPORT("gpu-committed", committedBytesUsed,
|
|
|
|
"Memory committed by the Windows graphics system.");
|
|
|
|
|
|
|
|
REPORT("gpu-dedicated", dedicatedBytesUsed,
|
|
|
|
"Out-of-process memory allocated for this process in a "
|
|
|
|
"physical GPU adapter's memory.");
|
|
|
|
|
|
|
|
REPORT("gpu-shared", sharedBytesUsed,
|
|
|
|
"In-process memory that is shared with the GPU.");
|
2013-11-06 03:58:20 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
#undef REPORT
|
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(GPUAdapterReporter, nsIMemoryReporter)
|
2013-12-08 05:39:47 +00:00
|
|
|
|
2015-01-28 01:09:34 +00:00
|
|
|
|
|
|
|
Atomic<size_t> gfxWindowsPlatform::sD3D11MemoryUsed;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3D11TextureReporter final : public nsIMemoryReporter
|
2015-01-28 01:09:34 +00:00
|
|
|
{
|
2015-01-30 01:55:00 +00:00
|
|
|
~D3D11TextureReporter() {}
|
|
|
|
|
2015-01-28 01:09:34 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback *aHandleReport,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2015-01-28 01:09:34 +00:00
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT("d3d11-shared-textures", KIND_OTHER, UNITS_BYTES,
|
|
|
|
gfxWindowsPlatform::sD3D11MemoryUsed,
|
|
|
|
"Memory used for D3D11 shared textures");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(D3D11TextureReporter, nsIMemoryReporter)
|
|
|
|
|
2015-02-03 08:34:33 +00:00
|
|
|
Atomic<size_t> gfxWindowsPlatform::sD3D9MemoryUsed;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3D9TextureReporter final : public nsIMemoryReporter
|
2015-02-03 08:34:33 +00:00
|
|
|
{
|
2015-02-16 11:37:43 +00:00
|
|
|
~D3D9TextureReporter() {}
|
|
|
|
|
2015-02-03 08:34:33 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback *aHandleReport,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2015-02-03 08:34:33 +00:00
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT("d3d9-shared-textures", KIND_OTHER, UNITS_BYTES,
|
|
|
|
gfxWindowsPlatform::sD3D9MemoryUsed,
|
|
|
|
"Memory used for D3D9 shared textures");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(D3D9TextureReporter, nsIMemoryReporter)
|
|
|
|
|
2015-02-05 03:20:14 +00:00
|
|
|
Atomic<size_t> gfxWindowsPlatform::sD3D9SurfaceImageUsed;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3D9SurfaceImageReporter final : public nsIMemoryReporter
|
2015-02-05 03:20:14 +00:00
|
|
|
{
|
2015-02-16 11:37:43 +00:00
|
|
|
~D3D9SurfaceImageReporter() {}
|
|
|
|
|
2015-02-05 03:20:14 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback *aHandleReport,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2015-02-05 03:20:14 +00:00
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT("d3d9-surface-image", KIND_OTHER, UNITS_BYTES,
|
|
|
|
gfxWindowsPlatform::sD3D9SurfaceImageUsed,
|
|
|
|
"Memory used for D3D9 surface images");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(D3D9SurfaceImageReporter, nsIMemoryReporter)
|
|
|
|
|
|
|
|
Atomic<size_t> gfxWindowsPlatform::sD3D9SharedTextureUsed;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3D9SharedTextureReporter final : public nsIMemoryReporter
|
2015-02-05 03:20:14 +00:00
|
|
|
{
|
2015-02-16 11:37:43 +00:00
|
|
|
~D3D9SharedTextureReporter() {}
|
|
|
|
|
2015-02-05 03:20:14 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback *aHandleReport,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2015-02-05 03:20:14 +00:00
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT("d3d9-shared-texture", KIND_OTHER, UNITS_BYTES,
|
|
|
|
gfxWindowsPlatform::sD3D9SharedTextureUsed,
|
|
|
|
"Memory used for D3D9 shared textures");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(D3D9SharedTextureReporter, nsIMemoryReporter)
|
|
|
|
|
2006-02-01 02:35:38 +00:00
|
|
|
gfxWindowsPlatform::gfxWindowsPlatform()
|
2013-11-21 22:07:56 +00:00
|
|
|
: mD3D11DeviceInitialized(false)
|
2015-01-21 03:36:01 +00:00
|
|
|
, mIsWARP(false)
|
2015-03-26 00:04:42 +00:00
|
|
|
, mCanInitMediaDevice(false)
|
2006-02-01 02:35:38 +00:00
|
|
|
{
|
2010-05-27 05:05:30 +00:00
|
|
|
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
|
|
|
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mUsingGDIFonts = false;
|
2010-11-08 11:02:27 +00:00
|
|
|
|
2010-08-26 20:44:53 +00:00
|
|
|
/*
|
|
|
|
* Initialize COM
|
|
|
|
*/
|
2013-07-31 15:44:31 +00:00
|
|
|
CoInitialize(nullptr);
|
2010-08-26 20:44:53 +00:00
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
2013-12-08 06:09:10 +00:00
|
|
|
RegisterStrongMemoryReporter(new GfxD2DSurfaceReporter());
|
2012-07-30 14:20:58 +00:00
|
|
|
mD2DDevice = nullptr;
|
2010-09-15 22:16:09 +00:00
|
|
|
#endif
|
2013-12-08 06:09:10 +00:00
|
|
|
RegisterStrongMemoryReporter(new GfxD2DVramReporter());
|
2010-09-15 22:16:09 +00:00
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
if (gfxPrefs::Direct2DUse1_1()) {
|
2014-10-23 16:53:13 +00:00
|
|
|
InitD3D11Devices();
|
2014-09-14 21:51:27 +00:00
|
|
|
}
|
2014-10-23 16:53:13 +00:00
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
UpdateRenderMode();
|
|
|
|
|
2014-04-27 01:36:00 +00:00
|
|
|
RegisterStrongMemoryReporter(new GPUAdapterReporter());
|
2015-01-28 01:09:34 +00:00
|
|
|
RegisterStrongMemoryReporter(new D3D11TextureReporter());
|
2015-02-03 08:34:33 +00:00
|
|
|
RegisterStrongMemoryReporter(new D3D9TextureReporter());
|
2015-02-05 03:20:14 +00:00
|
|
|
RegisterStrongMemoryReporter(new D3D9SurfaceImageReporter());
|
|
|
|
RegisterStrongMemoryReporter(new D3D9SharedTextureReporter());
|
2010-09-15 22:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxWindowsPlatform::~gfxWindowsPlatform()
|
|
|
|
{
|
2013-08-27 23:24:51 +00:00
|
|
|
mDeviceManager = nullptr;
|
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
// not calling FT_Done_FreeType because cairo may still hold references to
|
|
|
|
// these FT_Faces. See bug 458169.
|
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
if (mD2DDevice) {
|
|
|
|
cairo_release_device(mD2DDevice);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-25 19:00:31 +00:00
|
|
|
mozilla::gfx::Factory::D2DCleanup();
|
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
/*
|
|
|
|
* Uninitialize COM
|
|
|
|
*/
|
2010-11-08 11:02:27 +00:00
|
|
|
CoUninitialize();
|
2010-09-15 22:16:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-14 20:40:55 +00:00
|
|
|
double
|
|
|
|
gfxWindowsPlatform::GetDPIScale()
|
|
|
|
{
|
|
|
|
return WinUtils::LogToPhysFactor();
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
void
|
|
|
|
gfxWindowsPlatform::UpdateRenderMode()
|
|
|
|
{
|
2011-06-10 16:27:01 +00:00
|
|
|
/* Pick the default render mode for
|
|
|
|
* desktop.
|
2009-07-08 23:34:02 +00:00
|
|
|
*/
|
2015-01-28 00:54:19 +00:00
|
|
|
bool didReset = false;
|
2015-02-22 22:53:32 +00:00
|
|
|
DeviceResetReason resetReason = DeviceResetReason::OK;
|
|
|
|
if (DidRenderingDeviceReset(&resetReason)) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DEVICE_RESET_REASON, uint32_t(resetReason));
|
2015-01-08 00:10:49 +00:00
|
|
|
mD3D11DeviceInitialized = false;
|
|
|
|
mD3D11Device = nullptr;
|
|
|
|
mD3D11ContentDevice = nullptr;
|
2015-01-08 00:12:29 +00:00
|
|
|
mAdapter = nullptr;
|
2015-01-08 00:10:49 +00:00
|
|
|
|
|
|
|
imgLoader::Singleton()->ClearCache(true);
|
|
|
|
imgLoader::Singleton()->ClearCache(false);
|
|
|
|
Factory::SetDirect3D11Device(nullptr);
|
2015-01-28 00:54:19 +00:00
|
|
|
|
|
|
|
didReset = true;
|
2015-01-08 00:10:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 23:34:02 +00:00
|
|
|
mRenderMode = RENDER_GDI;
|
|
|
|
|
2013-11-22 03:35:40 +00:00
|
|
|
bool isVistaOrHigher = IsVistaOrLater();
|
2009-10-07 14:13:40 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool safeMode = false;
|
2010-08-31 00:02:18 +00:00
|
|
|
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
|
|
|
|
if (xr)
|
|
|
|
xr->GetInSafeMode(&safeMode);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
mUseDirectWrite = Preferences::GetBool("gfx.font_rendering.directwrite.enabled", false);
|
2010-09-15 22:16:09 +00:00
|
|
|
|
2010-06-30 13:52:13 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
2011-09-29 06:19:26 +00:00
|
|
|
bool d2dDisabled = false;
|
|
|
|
bool d2dForceEnabled = false;
|
|
|
|
bool d2dBlocked = false;
|
2010-08-30 21:45:29 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (gfxInfo) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t status;
|
2010-08-30 21:45:29 +00:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT2D, &status))) {
|
2014-07-01 21:44:09 +00:00
|
|
|
if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
2012-03-10 18:32:33 +00:00
|
|
|
d2dBlocked = true;
|
2010-08-30 21:45:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-24 19:44:52 +00:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS, &status))) {
|
|
|
|
if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
d2dBlocked = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 21:45:29 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 20:53:37 +00:00
|
|
|
// These will only be evaluated once, and any subsequent changes to
|
|
|
|
// the preferences will be ignored until restart.
|
2014-02-27 02:53:32 +00:00
|
|
|
d2dDisabled = gfxPrefs::Direct2DDisabled();
|
|
|
|
d2dForceEnabled = gfxPrefs::Direct2DForceEnabled();
|
2010-08-28 02:44:37 +00:00
|
|
|
|
2014-02-27 02:53:32 +00:00
|
|
|
bool tryD2D = d2dForceEnabled || (!d2dBlocked && !gfxPrefs::LayersPreferD3D9());
|
2012-07-18 01:53:12 +00:00
|
|
|
|
2010-11-08 11:02:27 +00:00
|
|
|
// Do not ever try if d2d is explicitly disabled,
|
|
|
|
// or if we're not using DWrite fonts.
|
|
|
|
if (d2dDisabled || mUsingGDIFonts) {
|
2010-09-15 22:16:09 +00:00
|
|
|
tryD2D = false;
|
|
|
|
}
|
2010-08-14 06:34:55 +00:00
|
|
|
|
2014-10-23 04:15:22 +00:00
|
|
|
ID3D11Device *device = GetD3D11Device();
|
2014-10-27 14:36:00 +00:00
|
|
|
if (isVistaOrHigher && !safeMode && tryD2D &&
|
|
|
|
device &&
|
|
|
|
device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_0 &&
|
2014-12-22 05:41:57 +00:00
|
|
|
DoesD3D11TextureSharingWork(device)) {
|
2014-10-23 04:15:22 +00:00
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
VerifyD2DDevice(d2dForceEnabled);
|
2014-11-24 20:40:29 +00:00
|
|
|
if (mD2DDevice && GetD3D11Device()) {
|
2010-09-15 22:16:09 +00:00
|
|
|
mRenderMode = RENDER_DIRECT2D;
|
2011-10-17 14:59:28 +00:00
|
|
|
mUseDirectWrite = true;
|
2010-08-14 06:34:55 +00:00
|
|
|
}
|
2010-09-15 22:16:09 +00:00
|
|
|
} else {
|
2012-07-30 14:20:58 +00:00
|
|
|
mD2DDevice = nullptr;
|
2010-08-14 06:34:55 +00:00
|
|
|
}
|
2010-06-30 13:52:13 +00:00
|
|
|
#endif
|
2010-08-14 06:34:55 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2010-08-14 06:34:55 +00:00
|
|
|
// Enable when it's preffed on -and- we're using Vista or higher. Or when
|
|
|
|
// we're going to use D2D.
|
2010-09-15 22:16:09 +00:00
|
|
|
if (!mDWriteFactory && (mUseDirectWrite && isVistaOrHigher)) {
|
2011-03-02 20:50:36 +00:00
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("DWrite");
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(DWriteCreateFactory)* createDWriteFactory = (decltype(DWriteCreateFactory)*)
|
2010-02-26 06:36:07 +00:00
|
|
|
GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory");
|
|
|
|
|
|
|
|
if (createDWriteFactory) {
|
|
|
|
/**
|
|
|
|
* I need a direct pointer to be able to cast to IUnknown**, I also
|
|
|
|
* need to remember to release this because the nsRefPtr will
|
|
|
|
* AddRef it.
|
|
|
|
*/
|
|
|
|
IDWriteFactory *factory;
|
|
|
|
HRESULT hr = createDWriteFactory(
|
|
|
|
DWRITE_FACTORY_TYPE_SHARED,
|
|
|
|
__uuidof(IDWriteFactory),
|
|
|
|
reinterpret_cast<IUnknown**>(&factory));
|
2011-03-02 20:50:36 +00:00
|
|
|
|
2012-09-11 03:35:25 +00:00
|
|
|
if (SUCCEEDED(hr) && factory) {
|
|
|
|
mDWriteFactory = factory;
|
|
|
|
factory->Release();
|
2011-12-06 12:39:19 +00:00
|
|
|
hr = mDWriteFactory->CreateTextAnalyzer(
|
|
|
|
getter_AddRefs(mDWriteAnalyzer));
|
|
|
|
}
|
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
SetupClearTypeParams();
|
2011-04-21 06:29:50 +00:00
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
if (hr == S_OK)
|
|
|
|
reporter.SetSuccessful();
|
2010-02-26 06:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-25 00:45:58 +00:00
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO);
|
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO);
|
|
|
|
BackendType defaultBackend = BackendType::CAIRO;
|
2012-07-25 00:45:58 +00:00
|
|
|
if (mRenderMode == RENDER_DIRECT2D) {
|
2014-01-10 19:06:16 +00:00
|
|
|
canvasMask |= BackendTypeBit(BackendType::DIRECT2D);
|
|
|
|
contentMask |= BackendTypeBit(BackendType::DIRECT2D);
|
2014-12-06 00:02:19 +00:00
|
|
|
if (gfxPrefs::Direct2DUse1_1() && Factory::SupportsD2D1() &&
|
|
|
|
GetD3D11ContentDevice()) {
|
2014-09-14 21:51:27 +00:00
|
|
|
contentMask |= BackendTypeBit(BackendType::DIRECT2D1_1);
|
2014-11-12 15:05:14 +00:00
|
|
|
canvasMask |= BackendTypeBit(BackendType::DIRECT2D1_1);
|
2014-09-14 21:51:27 +00:00
|
|
|
defaultBackend = BackendType::DIRECT2D1_1;
|
|
|
|
} else {
|
|
|
|
defaultBackend = BackendType::DIRECT2D;
|
|
|
|
}
|
2012-07-25 00:45:58 +00:00
|
|
|
} else {
|
2014-01-10 19:06:16 +00:00
|
|
|
canvasMask |= BackendTypeBit(BackendType::SKIA);
|
2012-07-25 00:45:58 +00:00
|
|
|
}
|
2014-04-09 14:40:44 +00:00
|
|
|
contentMask |= BackendTypeBit(BackendType::SKIA);
|
2013-11-05 19:54:12 +00:00
|
|
|
InitBackendPrefs(canvasMask, defaultBackend,
|
|
|
|
contentMask, defaultBackend);
|
2015-01-28 00:54:19 +00:00
|
|
|
|
|
|
|
if (didReset) {
|
|
|
|
mScreenReferenceDrawTarget = CreateOffscreenContentDrawTarget(IntSize(1, 1), SurfaceFormat::B8G8R8A8);
|
|
|
|
}
|
2006-02-24 05:15:21 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
HRESULT
|
|
|
|
gfxWindowsPlatform::CreateDevice(nsRefPtr<IDXGIAdapter1> &adapter1,
|
|
|
|
int featureLevelIndex)
|
|
|
|
{
|
|
|
|
nsModuleHandle d3d10module(LoadLibrarySystem32(L"d3d10_1.dll"));
|
|
|
|
if (!d3d10module)
|
|
|
|
return E_FAIL;
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(D3D10CreateDevice1)* createD3DDevice =
|
|
|
|
(decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module, "D3D10CreateDevice1");
|
2013-03-22 19:32:56 +00:00
|
|
|
if (!createD3DDevice)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Device1> device;
|
|
|
|
HRESULT hr =
|
2013-07-31 15:44:31 +00:00
|
|
|
createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr,
|
2014-04-03 05:29:22 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// This isn't set because of bug 1078411
|
|
|
|
// D3D10_CREATE_DEVICE_DEBUG |
|
|
|
|
#endif
|
2013-03-22 19:32:56 +00:00
|
|
|
D3D10_CREATE_DEVICE_BGRA_SUPPORT |
|
|
|
|
D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
|
|
|
|
static_cast<D3D10_FEATURE_LEVEL1>(kSupportedFeatureLevels[featureLevelIndex]),
|
|
|
|
D3D10_1_SDK_VERSION, getter_AddRefs(device));
|
|
|
|
|
|
|
|
// If we fail here, the DirectX version or video card probably
|
|
|
|
// changed. We previously could use 10.1 but now we can't
|
|
|
|
// anymore. Revert back to doing a 10.0 check first before
|
|
|
|
// the 10.1 check.
|
|
|
|
if (device) {
|
|
|
|
mD2DDevice = cairo_d2d_create_device_from_d3d10device(device);
|
|
|
|
|
2014-04-10 08:49:44 +00:00
|
|
|
// Setup a pref for future launch optimizaitons when in main process.
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
Preferences::SetInt(kFeatureLevelPref, featureLevelIndex);
|
|
|
|
}
|
2013-03-22 19:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return device ? S_OK : hr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
gfxWindowsPlatform::VerifyD2DDevice(bool aAttemptForce)
|
2006-02-24 05:15:21 +00:00
|
|
|
{
|
2010-08-10 23:59:51 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
if (mD2DDevice) {
|
2010-09-15 22:16:09 +00:00
|
|
|
ID3D10Device1 *device = cairo_d2d_device_get_device(mD2DDevice);
|
|
|
|
|
|
|
|
if (SUCCEEDED(device->GetDeviceRemovedReason())) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mD2DDevice = nullptr;
|
2014-02-08 19:37:39 +00:00
|
|
|
|
|
|
|
// Surface cache needs to be invalidated since it may contain vector
|
|
|
|
// images rendered with our old, broken D2D device.
|
|
|
|
SurfaceCache::DiscardAll();
|
2010-08-10 23:59:51 +00:00
|
|
|
}
|
2010-08-26 20:44:53 +00:00
|
|
|
|
2012-02-27 21:33:19 +00:00
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("D2D", aAttemptForce);
|
2011-03-02 20:50:36 +00:00
|
|
|
|
2010-09-15 22:16:09 +00:00
|
|
|
nsRefPtr<ID3D10Device1> device;
|
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
int supportedFeatureLevelsCount = ArrayLength(kSupportedFeatureLevels);
|
|
|
|
// If we're not running in Metro don't allow DX9.3
|
|
|
|
if (!IsRunningInWindowsMetro()) {
|
|
|
|
supportedFeatureLevelsCount--;
|
|
|
|
}
|
2011-08-09 19:38:26 +00:00
|
|
|
|
2013-05-01 14:27:09 +00:00
|
|
|
nsRefPtr<IDXGIAdapter1> adapter1 = GetDXGIAdapter();
|
|
|
|
|
|
|
|
if (!adapter1) {
|
|
|
|
// Unable to create adapter, abort acceleration.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
// It takes a lot of time (5-10% of startup time or ~100ms) to do both
|
|
|
|
// a createD3DDevice on D3D10_FEATURE_LEVEL_10_0. We therefore store
|
|
|
|
// the last used feature level to go direct to that.
|
|
|
|
int featureLevelIndex = Preferences::GetInt(kFeatureLevelPref, 0);
|
|
|
|
if (featureLevelIndex >= supportedFeatureLevelsCount || featureLevelIndex < 0)
|
|
|
|
featureLevelIndex = 0;
|
|
|
|
|
|
|
|
// Start with the last used feature level, and move to lower DX versions
|
|
|
|
// until we find one that works.
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
for (int i = featureLevelIndex; i < supportedFeatureLevelsCount; i++) {
|
|
|
|
hr = CreateDevice(adapter1, i);
|
|
|
|
// If it succeeded we found the first available feature level
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
break;
|
|
|
|
}
|
2012-11-09 02:34:44 +00:00
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
// If we succeeded in creating a device, try for a newer device
|
|
|
|
// that we haven't tried yet.
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
for (int i = featureLevelIndex - 1; i >= 0; i--) {
|
|
|
|
hr = CreateDevice(adapter1, i);
|
|
|
|
// If it failed then we don't have new hardware
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
break;
|
2012-11-09 02:34:44 +00:00
|
|
|
}
|
2013-03-22 19:32:56 +00:00
|
|
|
}
|
2010-09-15 22:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mD2DDevice && aAttemptForce) {
|
|
|
|
mD2DDevice = cairo_d2d_create_device();
|
|
|
|
}
|
2011-03-02 20:50:36 +00:00
|
|
|
|
2011-06-24 17:41:18 +00:00
|
|
|
if (mD2DDevice) {
|
2011-03-02 20:50:36 +00:00
|
|
|
reporter.SetSuccessful();
|
2011-06-24 17:41:18 +00:00
|
|
|
mozilla::gfx::Factory::SetDirect3D10Device(cairo_d2d_device_get_device(mD2DDevice));
|
|
|
|
}
|
2014-11-12 18:44:31 +00:00
|
|
|
|
|
|
|
ScopedGfxFeatureReporter reporter1_1("D2D1.1");
|
|
|
|
|
|
|
|
if (Factory::SupportsD2D1()) {
|
|
|
|
reporter1_1.SetSuccessful();
|
|
|
|
}
|
2010-09-15 22:16:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-11-08 11:02:27 +00:00
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxWindowsPlatform::CreatePlatformFontList()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mUsingGDIFonts = false;
|
2010-11-08 11:02:27 +00:00
|
|
|
gfxPlatformFontList *pfl;
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2014-02-11 21:01:30 +00:00
|
|
|
// bug 630201 - older pre-RTM versions of Direct2D/DirectWrite cause odd
|
|
|
|
// crashers so blacklist them altogether
|
2014-02-12 14:49:06 +00:00
|
|
|
if (IsNotWin7PreRTM() && GetDWriteFactory()) {
|
2010-11-08 11:02:27 +00:00
|
|
|
pfl = new gfxDWriteFontList();
|
|
|
|
if (NS_SUCCEEDED(pfl->InitFontList())) {
|
|
|
|
return pfl;
|
|
|
|
}
|
|
|
|
// DWrite font initialization failed! Don't know why this would happen,
|
|
|
|
// but apparently it can - see bug 594865.
|
|
|
|
// So we're going to fall back to GDI fonts & rendering.
|
|
|
|
gfxPlatformFontList::Shutdown();
|
|
|
|
SetRenderMode(RENDER_GDI);
|
2010-02-26 06:36:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-11-08 11:02:27 +00:00
|
|
|
pfl = new gfxGDIFontList();
|
2011-10-17 14:59:28 +00:00
|
|
|
mUsingGDIFonts = true;
|
2010-11-08 11:02:27 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(pfl->InitFontList())) {
|
|
|
|
return pfl;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformFontList::Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-07 14:13:40 +00:00
|
|
|
}
|
2010-02-26 06:36:07 +00:00
|
|
|
|
2006-03-25 00:34:48 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
2014-02-09 08:04:38 +00:00
|
|
|
gfxWindowsPlatform::CreateOffscreenSurface(const IntSize& size,
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxContentType contentType)
|
2006-02-01 02:35:38 +00:00
|
|
|
{
|
2012-07-31 07:57:28 +00:00
|
|
|
nsRefPtr<gfxASurface> surf = nullptr;
|
2009-07-08 23:34:02 +00:00
|
|
|
|
|
|
|
#ifdef CAIRO_HAS_WIN32_SURFACE
|
|
|
|
if (mRenderMode == RENDER_GDI)
|
2015-03-29 14:59:15 +00:00
|
|
|
surf = new gfxWindowsSurface(size,
|
2014-02-09 08:04:38 +00:00
|
|
|
OptimalFormatForContent(contentType));
|
2009-01-15 00:19:39 +00:00
|
|
|
#endif
|
2009-07-08 23:34:02 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
if (mRenderMode == RENDER_DIRECT2D)
|
2015-03-29 14:59:15 +00:00
|
|
|
surf = new gfxD2DSurface(size,
|
2014-02-09 08:04:38 +00:00
|
|
|
OptimalFormatForContent(contentType));
|
2010-02-26 06:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-31 07:57:28 +00:00
|
|
|
if (!surf || surf->CairoStatus()) {
|
2015-03-29 14:59:15 +00:00
|
|
|
surf = new gfxImageSurface(size,
|
2014-02-09 08:04:38 +00:00
|
|
|
OptimalFormatForContent(contentType));
|
2012-07-31 07:57:28 +00:00
|
|
|
}
|
2009-07-08 23:34:02 +00:00
|
|
|
|
2012-07-31 07:57:28 +00:00
|
|
|
return surf.forget();
|
2012-06-25 21:44:41 +00:00
|
|
|
}
|
|
|
|
|
2012-09-24 15:02:49 +00:00
|
|
|
TemporaryRef<ScaledFont>
|
2012-07-24 10:18:37 +00:00
|
|
|
gfxWindowsPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-06-24 17:41:18 +00:00
|
|
|
{
|
2012-04-11 14:55:31 +00:00
|
|
|
if (aFont->GetType() == gfxFont::FONT_TYPE_DWRITE) {
|
|
|
|
gfxDWriteFont *font = static_cast<gfxDWriteFont*>(aFont);
|
2011-06-24 17:41:18 +00:00
|
|
|
|
2012-04-11 14:55:31 +00:00
|
|
|
NativeFont nativeFont;
|
2014-01-10 19:06:16 +00:00
|
|
|
nativeFont.mType = NativeFontType::DWRITE_FONT_FACE;
|
2012-04-11 14:55:31 +00:00
|
|
|
nativeFont.mFont = font->GetFontFace();
|
2011-06-24 17:41:18 +00:00
|
|
|
|
2014-06-19 20:35:33 +00:00
|
|
|
if (aTarget->GetBackendType() == BackendType::CAIRO) {
|
2012-08-08 20:17:04 +00:00
|
|
|
return Factory::CreateScaledFontWithCairo(nativeFont,
|
|
|
|
font->GetAdjustedSize(),
|
|
|
|
font->GetCairoScaledFont());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont,
|
|
|
|
font->GetAdjustedSize());
|
2012-04-11 14:55:31 +00:00
|
|
|
}
|
2011-06-30 12:35:46 +00:00
|
|
|
|
2012-04-11 14:55:31 +00:00
|
|
|
NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_GDI,
|
|
|
|
"Fonts on windows should be GDI or DWrite!");
|
|
|
|
|
|
|
|
NativeFont nativeFont;
|
2014-01-10 19:06:16 +00:00
|
|
|
nativeFont.mType = NativeFontType::GDI_FONT_FACE;
|
2012-04-11 14:55:31 +00:00
|
|
|
LOGFONT lf;
|
|
|
|
GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf);
|
|
|
|
nativeFont.mFont = &lf;
|
2011-11-18 04:00:37 +00:00
|
|
|
|
2014-06-19 20:35:33 +00:00
|
|
|
if (aTarget->GetBackendType() == BackendType::CAIRO) {
|
2012-07-24 10:18:37 +00:00
|
|
|
return Factory::CreateScaledFontWithCairo(nativeFont,
|
|
|
|
aFont->GetAdjustedSize(),
|
|
|
|
aFont->GetCairoScaledFont());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
|
2011-06-24 17:41:18 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 02:35:38 +00:00
|
|
|
nsresult
|
2010-02-24 17:57:57 +00:00
|
|
|
gfxWindowsPlatform::GetFontList(nsIAtom *aLangGroup,
|
2006-02-01 02:35:38 +00:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-02-01 02:35:38 +00:00
|
|
|
{
|
2009-10-07 14:13:40 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
|
2006-02-24 05:15:21 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-15 04:47:23 +00:00
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::UpdateFontList()
|
|
|
|
{
|
2009-10-07 14:13:40 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2008-03-13 02:36:58 +00:00
|
|
|
|
2006-06-15 04:47:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontAparajita[] = "Aparajita";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontArabicTypesetting[] = "Arabic Typesetting";
|
|
|
|
static const char kFontArial[] = "Arial";
|
|
|
|
static const char kFontArialUnicodeMS[] = "Arial Unicode MS";
|
|
|
|
static const char kFontCambria[] = "Cambria";
|
|
|
|
static const char kFontCambriaMath[] = "Cambria Math";
|
|
|
|
static const char kFontEbrima[] = "Ebrima";
|
|
|
|
static const char kFontEstrangeloEdessa[] = "Estrangelo Edessa";
|
|
|
|
static const char kFontEuphemia[] = "Euphemia";
|
|
|
|
static const char kFontGabriola[] = "Gabriola";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontJavaneseText[] = "Javanese Text";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontKhmerUI[] = "Khmer UI";
|
|
|
|
static const char kFontLaoUI[] = "Lao UI";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontLeelawadeeUI[] = "Leelawadee UI";
|
2012-06-14 06:31:56 +00:00
|
|
|
static const char kFontLucidaSansUnicode[] = "Lucida Sans Unicode";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontMVBoli[] = "MV Boli";
|
|
|
|
static const char kFontMalgunGothic[] = "Malgun Gothic";
|
|
|
|
static const char kFontMicrosoftJhengHei[] = "Microsoft JhengHei";
|
|
|
|
static const char kFontMicrosoftNewTaiLue[] = "Microsoft New Tai Lue";
|
|
|
|
static const char kFontMicrosoftPhagsPa[] = "Microsoft PhagsPa";
|
|
|
|
static const char kFontMicrosoftTaiLe[] = "Microsoft Tai Le";
|
|
|
|
static const char kFontMicrosoftUighur[] = "Microsoft Uighur";
|
|
|
|
static const char kFontMicrosoftYaHei[] = "Microsoft YaHei";
|
|
|
|
static const char kFontMicrosoftYiBaiti[] = "Microsoft Yi Baiti";
|
|
|
|
static const char kFontMeiryo[] = "Meiryo";
|
|
|
|
static const char kFontMongolianBaiti[] = "Mongolian Baiti";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontMyanmarText[] = "Myanmar Text";
|
|
|
|
static const char kFontNirmalaUI[] = "Nirmala UI";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontNyala[] = "Nyala";
|
|
|
|
static const char kFontPlantagenetCherokee[] = "Plantagenet Cherokee";
|
2012-03-09 02:05:55 +00:00
|
|
|
static const char kFontSegoeUI[] = "Segoe UI";
|
2014-05-26 08:09:55 +00:00
|
|
|
static const char kFontSegoeUIEmoji[] = "Segoe UI Emoji";
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontSegoeUISymbol[] = "Segoe UI Symbol";
|
|
|
|
static const char kFontSylfaen[] = "Sylfaen";
|
|
|
|
static const char kFontTraditionalArabic[] = "Traditional Arabic";
|
2014-04-14 23:45:18 +00:00
|
|
|
static const char kFontUtsaah[] = "Utsaah";
|
|
|
|
static const char kFontYuGothic[] = "Yu Gothic";
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
void
|
2014-09-30 06:27:55 +00:00
|
|
|
gfxWindowsPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aRunScript,
|
2012-03-09 02:05:24 +00:00
|
|
|
nsTArray<const char*>& aFontList)
|
|
|
|
{
|
2014-09-30 06:27:55 +00:00
|
|
|
if (aNextCh == 0xfe0fu) {
|
|
|
|
aFontList.AppendElement(kFontSegoeUIEmoji);
|
|
|
|
}
|
|
|
|
|
2012-03-09 02:05:55 +00:00
|
|
|
// Arial is used as the default fallback for system fallback
|
|
|
|
aFontList.AppendElement(kFontArial);
|
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
if (!IS_IN_BMP(aCh)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t p = aCh >> 16;
|
2012-03-09 02:05:24 +00:00
|
|
|
if (p == 1) { // SMP plane
|
2014-09-30 06:27:55 +00:00
|
|
|
if (aNextCh == 0xfe0eu) {
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
|
|
|
aFontList.AppendElement(kFontSegoeUIEmoji);
|
|
|
|
} else {
|
|
|
|
if (aNextCh != 0xfe0fu) {
|
|
|
|
aFontList.AppendElement(kFontSegoeUIEmoji);
|
|
|
|
}
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
|
|
|
}
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontEbrima);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontNirmalaUI);
|
2012-06-14 06:31:56 +00:00
|
|
|
aFontList.AppendElement(kFontCambriaMath);
|
2012-03-09 02:05:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t b = (aCh >> 8) & 0xff;
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
switch (b) {
|
|
|
|
case 0x05:
|
|
|
|
aFontList.AppendElement(kFontEstrangeloEdessa);
|
|
|
|
aFontList.AppendElement(kFontCambria);
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftUighur);
|
|
|
|
break;
|
|
|
|
case 0x07:
|
|
|
|
aFontList.AppendElement(kFontEstrangeloEdessa);
|
|
|
|
aFontList.AppendElement(kFontMVBoli);
|
|
|
|
aFontList.AppendElement(kFontEbrima);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x09:
|
2014-04-23 12:34:14 +00:00
|
|
|
aFontList.AppendElement(kFontNirmalaUI);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontUtsaah);
|
|
|
|
aFontList.AppendElement(kFontAparajita);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x0e:
|
|
|
|
aFontList.AppendElement(kFontLaoUI);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x10:
|
|
|
|
aFontList.AppendElement(kFontMyanmarText);
|
|
|
|
break;
|
|
|
|
case 0x11:
|
|
|
|
aFontList.AppendElement(kFontMalgunGothic);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x12:
|
|
|
|
case 0x13:
|
|
|
|
aFontList.AppendElement(kFontNyala);
|
|
|
|
aFontList.AppendElement(kFontPlantagenetCherokee);
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
case 0x15:
|
|
|
|
case 0x16:
|
|
|
|
aFontList.AppendElement(kFontEuphemia);
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
|
|
|
break;
|
|
|
|
case 0x17:
|
|
|
|
aFontList.AppendElement(kFontKhmerUI);
|
|
|
|
break;
|
|
|
|
case 0x18: // Mongolian
|
|
|
|
aFontList.AppendElement(kFontMongolianBaiti);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontEuphemia);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0x19:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftTaiLe);
|
|
|
|
aFontList.AppendElement(kFontMicrosoftNewTaiLue);
|
|
|
|
aFontList.AppendElement(kFontKhmerUI);
|
|
|
|
break;
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x1a:
|
|
|
|
aFontList.AppendElement(kFontLeelawadeeUI);
|
|
|
|
break;
|
|
|
|
case 0x1c:
|
|
|
|
aFontList.AppendElement(kFontNirmalaUI);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0x20: // Symbol ranges
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
case 0x24:
|
|
|
|
case 0x25:
|
|
|
|
case 0x26:
|
|
|
|
case 0x27:
|
|
|
|
case 0x29:
|
|
|
|
case 0x2a:
|
|
|
|
case 0x2b:
|
|
|
|
case 0x2c:
|
2012-03-09 02:05:55 +00:00
|
|
|
aFontList.AppendElement(kFontSegoeUI);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
2012-03-09 02:05:55 +00:00
|
|
|
aFontList.AppendElement(kFontCambria);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontMeiryo);
|
|
|
|
aFontList.AppendElement(kFontArial);
|
2012-06-14 06:31:56 +00:00
|
|
|
aFontList.AppendElement(kFontLucidaSansUnicode);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontEbrima);
|
|
|
|
break;
|
|
|
|
case 0x2d:
|
|
|
|
case 0x2e:
|
|
|
|
case 0x2f:
|
|
|
|
aFontList.AppendElement(kFontEbrima);
|
|
|
|
aFontList.AppendElement(kFontNyala);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontSegoeUI);
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontMeiryo);
|
|
|
|
break;
|
|
|
|
case 0x28: // Braille
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
|
|
|
break;
|
|
|
|
case 0x30:
|
|
|
|
case 0x31:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftYaHei);
|
|
|
|
break;
|
|
|
|
case 0x32:
|
|
|
|
aFontList.AppendElement(kFontMalgunGothic);
|
|
|
|
break;
|
|
|
|
case 0x4d:
|
|
|
|
aFontList.AppendElement(kFontSegoeUISymbol);
|
|
|
|
break;
|
2014-04-14 23:45:18 +00:00
|
|
|
case 0x9f:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftYaHei);
|
|
|
|
aFontList.AppendElement(kFontYuGothic);
|
|
|
|
break;
|
2012-03-09 02:05:24 +00:00
|
|
|
case 0xa0: // Yi
|
|
|
|
case 0xa1:
|
|
|
|
case 0xa2:
|
|
|
|
case 0xa3:
|
|
|
|
case 0xa4:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftYiBaiti);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontSegoeUI);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0xa5:
|
|
|
|
case 0xa6:
|
|
|
|
case 0xa7:
|
|
|
|
aFontList.AppendElement(kFontEbrima);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontSegoeUI);
|
2012-03-09 02:05:24 +00:00
|
|
|
aFontList.AppendElement(kFontCambriaMath);
|
|
|
|
break;
|
|
|
|
case 0xa8:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftPhagsPa);
|
2014-04-14 23:45:18 +00:00
|
|
|
aFontList.AppendElement(kFontNirmalaUI);
|
|
|
|
break;
|
|
|
|
case 0xa9:
|
|
|
|
aFontList.AppendElement(kFontMalgunGothic);
|
|
|
|
aFontList.AppendElement(kFontJavaneseText);
|
|
|
|
break;
|
|
|
|
case 0xaa:
|
|
|
|
aFontList.AppendElement(kFontMyanmarText);
|
|
|
|
break;
|
|
|
|
case 0xab:
|
|
|
|
aFontList.AppendElement(kFontEbrima);
|
|
|
|
aFontList.AppendElement(kFontNyala);
|
|
|
|
break;
|
|
|
|
case 0xd7:
|
|
|
|
aFontList.AppendElement(kFontMalgunGothic);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0xfb:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftUighur);
|
|
|
|
aFontList.AppendElement(kFontGabriola);
|
|
|
|
aFontList.AppendElement(kFontSylfaen);
|
|
|
|
break;
|
|
|
|
case 0xfc:
|
|
|
|
case 0xfd:
|
|
|
|
aFontList.AppendElement(kFontTraditionalArabic);
|
2012-03-09 02:05:55 +00:00
|
|
|
aFontList.AppendElement(kFontArabicTypesetting);
|
2012-03-09 02:05:24 +00:00
|
|
|
break;
|
|
|
|
case 0xfe:
|
|
|
|
aFontList.AppendElement(kFontTraditionalArabic);
|
|
|
|
aFontList.AppendElement(kFontMicrosoftJhengHei);
|
|
|
|
break;
|
|
|
|
case 0xff:
|
|
|
|
aFontList.AppendElement(kFontMicrosoftJhengHei);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arial Unicode MS has lots of glyphs for obscure characters,
|
|
|
|
// use it as a last resort
|
|
|
|
aFontList.AppendElement(kFontArialUnicodeMS);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
2007-05-29 15:09:23 +00:00
|
|
|
{
|
2009-10-07 14:13:40 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
return NS_OK;
|
2006-02-01 02:35:38 +00:00
|
|
|
}
|
2007-04-02 19:06:16 +00:00
|
|
|
|
|
|
|
gfxFontGroup *
|
2014-06-06 06:09:23 +00:00
|
|
|
gfxWindowsPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2008-10-01 03:01:53 +00:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
|
|
|
{
|
2014-06-06 06:09:23 +00:00
|
|
|
return new gfxFontGroup(aFontFamilyList, aStyle, aUserFontSet);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxWindowsPlatform::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
|
|
|
aItalic);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxWindowsPlatform::MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic,
|
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
|
|
|
aItalic,
|
2009-10-07 14:13:40 +00:00
|
|
|
aFontData,
|
|
|
|
aLength);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxWindowsPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-01-13 05:16:58 +00:00
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
2014-10-04 10:36:05 +00:00
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// no format hint set, need to look at data
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-04-02 19:06:16 +00:00
|
|
|
}
|
2007-05-30 00:07:03 +00:00
|
|
|
|
2015-03-26 04:01:31 +00:00
|
|
|
static DeviceResetReason HResultToResetReason(HRESULT hr)
|
|
|
|
{
|
|
|
|
switch (hr) {
|
|
|
|
case DXGI_ERROR_DEVICE_HUNG:
|
|
|
|
return DeviceResetReason::HUNG;
|
|
|
|
case DXGI_ERROR_DEVICE_REMOVED:
|
|
|
|
return DeviceResetReason::REMOVED;
|
|
|
|
case DXGI_ERROR_DEVICE_RESET:
|
|
|
|
return DeviceResetReason::RESET;
|
|
|
|
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
|
|
|
|
return DeviceResetReason::DRIVER_ERROR;
|
|
|
|
case DXGI_ERROR_INVALID_CALL:
|
|
|
|
return DeviceResetReason::INVALID_CALL;
|
|
|
|
case E_OUTOFMEMORY:
|
|
|
|
return DeviceResetReason::OUT_OF_MEMORY;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
}
|
|
|
|
return DeviceResetReason::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2014-09-24 17:12:10 +00:00
|
|
|
bool
|
2015-02-22 22:53:32 +00:00
|
|
|
gfxWindowsPlatform::DidRenderingDeviceReset(DeviceResetReason* aResetReason)
|
2014-09-24 17:12:10 +00:00
|
|
|
{
|
2015-02-22 22:53:32 +00:00
|
|
|
if (aResetReason) {
|
|
|
|
*aResetReason = DeviceResetReason::OK;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:10:49 +00:00
|
|
|
if (mD3D11Device) {
|
2015-02-22 22:53:32 +00:00
|
|
|
HRESULT hr = mD3D11Device->GetDeviceRemovedReason();
|
|
|
|
if (hr != S_OK) {
|
|
|
|
if (aResetReason) {
|
2015-03-26 04:01:31 +00:00
|
|
|
*aResetReason = HResultToResetReason(hr);
|
2015-02-22 22:53:32 +00:00
|
|
|
}
|
2015-01-08 00:10:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mD3D11ContentDevice) {
|
2015-03-26 04:01:31 +00:00
|
|
|
HRESULT hr = mD3D11ContentDevice->GetDeviceRemovedReason();
|
|
|
|
if (hr != S_OK) {
|
|
|
|
if (aResetReason) {
|
|
|
|
*aResetReason = HResultToResetReason(hr);
|
|
|
|
}
|
2015-01-08 00:10:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (GetD3D10Device()) {
|
2015-03-26 04:01:31 +00:00
|
|
|
HRESULT hr = GetD3D10Device()->GetDeviceRemovedReason();
|
|
|
|
if (hr != S_OK) {
|
|
|
|
if (aResetReason) {
|
|
|
|
*aResetReason = HResultToResetReason(hr);
|
|
|
|
}
|
2015-01-08 00:10:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-09-24 17:12:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
void
|
|
|
|
gfxWindowsPlatform::GetPlatformCMSOutputProfile(void* &mem, size_t &mem_size)
|
2007-07-23 22:02:17 +00:00
|
|
|
{
|
2010-01-24 13:58:31 +00:00
|
|
|
WCHAR str[MAX_PATH];
|
|
|
|
DWORD size = MAX_PATH;
|
|
|
|
BOOL res;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2013-11-07 10:20:08 +00:00
|
|
|
mem = nullptr;
|
|
|
|
mem_size = 0;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
HDC dc = GetDC(nullptr);
|
2010-01-05 23:39:56 +00:00
|
|
|
if (!dc)
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
2010-01-05 23:39:56 +00:00
|
|
|
|
2014-06-23 16:04:22 +00:00
|
|
|
MOZ_SEH_TRY {
|
2010-01-24 13:58:31 +00:00
|
|
|
res = GetICMProfileW(dc, &size, (LPWSTR)&str);
|
2014-06-23 16:04:22 +00:00
|
|
|
} MOZ_SEH_EXCEPT(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
|
2010-01-24 13:58:31 +00:00
|
|
|
res = FALSE;
|
2010-01-05 23:39:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
ReleaseDC(nullptr, dc);
|
2010-01-24 13:58:31 +00:00
|
|
|
if (!res)
|
2013-11-07 10:20:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
qcms_data_from_unicode_path(str, &mem, &mem_size);
|
2007-07-23 22:02:17 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_tor
|
2013-11-07 10:20:08 +00:00
|
|
|
if (mem_size > 0)
|
2007-07-23 22:02:17 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
NS_ConvertUTF16toUTF8(str).get());
|
2013-11-07 10:20:08 +00:00
|
|
|
#endif // DEBUG_tor
|
|
|
|
#endif // _WIN32
|
2007-07-23 22:02:17 +00:00
|
|
|
}
|
2007-08-24 19:41:16 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-05-27 05:05:30 +00:00
|
|
|
gfxWindowsPlatform::UseClearTypeForDownloadableFonts()
|
|
|
|
{
|
|
|
|
if (mUseClearTypeForDownloadableFonts == UNINITIALIZED_VALUE) {
|
2011-09-29 06:19:26 +00:00
|
|
|
mUseClearTypeForDownloadableFonts = Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, true);
|
2010-05-27 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mUseClearTypeForDownloadableFonts;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-05-27 05:05:30 +00:00
|
|
|
gfxWindowsPlatform::UseClearTypeAlways()
|
|
|
|
{
|
|
|
|
if (mUseClearTypeAlways == UNINITIALIZED_VALUE) {
|
2011-09-29 06:19:26 +00:00
|
|
|
mUseClearTypeAlways = Preferences::GetBool(GFX_USE_CLEARTYPE_ALWAYS, false);
|
2010-05-27 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mUseClearTypeAlways;
|
|
|
|
}
|
|
|
|
|
2011-01-14 12:57:17 +00:00
|
|
|
void
|
2013-12-11 09:46:41 +00:00
|
|
|
gfxWindowsPlatform::GetDLLVersion(char16ptr_t aDLLPath, nsAString& aVersion)
|
2011-01-14 12:57:17 +00:00
|
|
|
{
|
|
|
|
DWORD versInfoSize, vers[4] = {0};
|
|
|
|
// version info not available case
|
2014-05-26 18:54:10 +00:00
|
|
|
aVersion.AssignLiteral(MOZ_UTF16("0.0.0.0"));
|
2013-07-31 15:44:31 +00:00
|
|
|
versInfoSize = GetFileVersionInfoSizeW(aDLLPath, nullptr);
|
2011-01-14 12:57:17 +00:00
|
|
|
nsAutoTArray<BYTE,512> versionInfo;
|
|
|
|
|
2011-02-15 02:28:51 +00:00
|
|
|
if (versInfoSize == 0 ||
|
2012-08-22 15:56:38 +00:00
|
|
|
!versionInfo.AppendElements(uint32_t(versInfoSize)))
|
2011-02-15 02:28:51 +00:00
|
|
|
{
|
2011-01-14 12:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-02-15 02:28:51 +00:00
|
|
|
|
2011-01-28 10:35:40 +00:00
|
|
|
if (!GetFileVersionInfoW(aDLLPath, 0, versInfoSize,
|
2011-02-15 02:28:51 +00:00
|
|
|
LPBYTE(versionInfo.Elements())))
|
|
|
|
{
|
2011-01-14 12:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-15 02:28:51 +00:00
|
|
|
UINT len = 0;
|
2012-07-30 14:20:58 +00:00
|
|
|
VS_FIXEDFILEINFO *fileInfo = nullptr;
|
2011-01-14 12:57:17 +00:00
|
|
|
if (!VerQueryValue(LPBYTE(versionInfo.Elements()), TEXT("\\"),
|
2011-02-15 02:28:51 +00:00
|
|
|
(LPVOID *)&fileInfo, &len) ||
|
|
|
|
len == 0 ||
|
2012-07-30 14:20:58 +00:00
|
|
|
fileInfo == nullptr)
|
2011-02-15 02:28:51 +00:00
|
|
|
{
|
2011-01-14 12:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD fileVersMS = fileInfo->dwFileVersionMS;
|
|
|
|
DWORD fileVersLS = fileInfo->dwFileVersionLS;
|
|
|
|
|
|
|
|
vers[0] = HIWORD(fileVersMS);
|
|
|
|
vers[1] = LOWORD(fileVersMS);
|
|
|
|
vers[2] = HIWORD(fileVersLS);
|
|
|
|
vers[3] = LOWORD(fileVersLS);
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "%d.%d.%d.%d", vers[0], vers[1], vers[2], vers[3]);
|
|
|
|
aVersion.Assign(NS_ConvertUTF8toUTF16(buf));
|
|
|
|
}
|
|
|
|
|
2011-05-11 00:30:20 +00:00
|
|
|
void
|
|
|
|
gfxWindowsPlatform::GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams)
|
|
|
|
{
|
|
|
|
HKEY hKey, subKey;
|
|
|
|
DWORD i, rv, size, type;
|
|
|
|
WCHAR displayName[256], subkeyName[256];
|
|
|
|
|
|
|
|
aParams.Clear();
|
|
|
|
|
|
|
|
// construct subkeys based on HKLM subkeys, assume they are same for HKCU
|
|
|
|
rv = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"Software\\Microsoft\\Avalon.Graphics",
|
|
|
|
0, KEY_READ, &hKey);
|
|
|
|
|
|
|
|
if (rv != ERROR_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enumerate over subkeys
|
|
|
|
for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
|
2011-10-11 05:50:08 +00:00
|
|
|
size = ArrayLength(displayName);
|
2013-07-31 15:44:31 +00:00
|
|
|
rv = RegEnumKeyExW(hKey, i, displayName, &size,
|
|
|
|
nullptr, nullptr, nullptr, nullptr);
|
2011-05-11 00:30:20 +00:00
|
|
|
if (rv != ERROR_SUCCESS) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearTypeParameterInfo ctinfo;
|
|
|
|
ctinfo.displayName.Assign(displayName);
|
|
|
|
|
|
|
|
DWORD subrv, value;
|
|
|
|
bool foundData = false;
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
swprintf_s(subkeyName, ArrayLength(subkeyName),
|
2011-05-11 00:30:20 +00:00
|
|
|
L"Software\\Microsoft\\Avalon.Graphics\\%s", displayName);
|
|
|
|
|
|
|
|
// subkey for gamma, pixel structure
|
|
|
|
subrv = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
subkeyName, 0, KEY_QUERY_VALUE, &subKey);
|
|
|
|
|
|
|
|
if (subrv == ERROR_SUCCESS) {
|
|
|
|
size = sizeof(value);
|
2013-07-31 15:44:31 +00:00
|
|
|
subrv = RegQueryValueExW(subKey, L"GammaLevel", nullptr, &type,
|
2011-05-11 00:30:20 +00:00
|
|
|
(LPBYTE)&value, &size);
|
|
|
|
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
|
|
|
|
foundData = true;
|
|
|
|
ctinfo.gamma = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(value);
|
2013-07-31 15:44:31 +00:00
|
|
|
subrv = RegQueryValueExW(subKey, L"PixelStructure", nullptr, &type,
|
2011-05-11 00:30:20 +00:00
|
|
|
(LPBYTE)&value, &size);
|
|
|
|
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
|
|
|
|
foundData = true;
|
|
|
|
ctinfo.pixelStructure = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
// subkey for cleartype level, enhanced contrast
|
|
|
|
subrv = RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
subkeyName, 0, KEY_QUERY_VALUE, &subKey);
|
|
|
|
|
|
|
|
if (subrv == ERROR_SUCCESS) {
|
|
|
|
size = sizeof(value);
|
2013-07-31 15:44:31 +00:00
|
|
|
subrv = RegQueryValueExW(subKey, L"ClearTypeLevel", nullptr, &type,
|
2011-05-11 00:30:20 +00:00
|
|
|
(LPBYTE)&value, &size);
|
|
|
|
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
|
|
|
|
foundData = true;
|
|
|
|
ctinfo.clearTypeLevel = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(value);
|
|
|
|
subrv = RegQueryValueExW(subKey, L"EnhancedContrastLevel",
|
2013-07-31 15:44:31 +00:00
|
|
|
nullptr, &type, (LPBYTE)&value, &size);
|
2011-05-11 00:30:20 +00:00
|
|
|
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
|
|
|
|
foundData = true;
|
|
|
|
ctinfo.enhancedContrast = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundData) {
|
|
|
|
aParams.AppendElement(ctinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
2010-05-27 05:05:30 +00:00
|
|
|
void
|
2011-06-12 02:30:16 +00:00
|
|
|
gfxWindowsPlatform::FontsPrefsChanged(const char *aPref)
|
2010-05-27 05:05:30 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool clearTextFontCaches = true;
|
2010-05-27 05:05:30 +00:00
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
gfxPlatform::FontsPrefsChanged(aPref);
|
2010-05-27 05:05:30 +00:00
|
|
|
|
|
|
|
if (!aPref) {
|
|
|
|
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
|
|
|
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
|
|
|
} else if (!strcmp(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, aPref)) {
|
|
|
|
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
|
|
|
} else if (!strcmp(GFX_USE_CLEARTYPE_ALWAYS, aPref)) {
|
|
|
|
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
2011-04-21 06:29:50 +00:00
|
|
|
} else if (!strncmp(GFX_CLEARTYPE_PARAMS, aPref, strlen(GFX_CLEARTYPE_PARAMS))) {
|
2011-06-12 02:30:16 +00:00
|
|
|
SetupClearTypeParams();
|
2010-05-27 05:05:30 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
clearTextFontCaches = false;
|
2010-05-27 05:05:30 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:33:13 +00:00
|
|
|
if (clearTextFontCaches) {
|
2010-05-27 05:05:30 +00:00
|
|
|
gfxFontCache *fc = gfxFontCache::GetCache();
|
2010-06-09 00:33:13 +00:00
|
|
|
if (fc) {
|
|
|
|
fc->Flush();
|
|
|
|
}
|
2010-05-27 05:05:30 +00:00
|
|
|
}
|
2010-08-14 12:43:27 +00:00
|
|
|
}
|
2011-03-02 01:00:33 +00:00
|
|
|
|
2012-03-19 19:20:18 +00:00
|
|
|
#define ENHANCED_CONTRAST_REGISTRY_KEY \
|
|
|
|
HKEY_CURRENT_USER, "Software\\Microsoft\\Avalon.Graphics\\DISPLAY1\\EnhancedContrastLevel"
|
|
|
|
|
2011-04-21 06:29:50 +00:00
|
|
|
void
|
2011-06-12 02:30:16 +00:00
|
|
|
gfxWindowsPlatform::SetupClearTypeParams()
|
2011-04-21 06:29:50 +00:00
|
|
|
{
|
|
|
|
#if CAIRO_HAS_DWRITE_FONT
|
|
|
|
if (GetDWriteFactory()) {
|
|
|
|
// any missing prefs will default to invalid (-1) and be ignored;
|
|
|
|
// out-of-range values will also be ignored
|
|
|
|
FLOAT gamma = -1.0;
|
|
|
|
FLOAT contrast = -1.0;
|
|
|
|
FLOAT level = -1.0;
|
|
|
|
int geometry = -1;
|
|
|
|
int mode = -1;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t value;
|
2011-06-12 02:30:16 +00:00
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_GAMMA, &value))) {
|
2011-04-21 06:29:50 +00:00
|
|
|
if (value >= 1000 && value <= 2200) {
|
2011-05-11 00:30:20 +00:00
|
|
|
gamma = FLOAT(value / 1000.0);
|
2011-04-21 06:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-12 02:30:16 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_CONTRAST, &value))) {
|
2011-04-21 06:29:50 +00:00
|
|
|
if (value >= 0 && value <= 1000) {
|
2011-05-11 00:30:20 +00:00
|
|
|
contrast = FLOAT(value / 100.0);
|
2011-04-21 06:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-12 02:30:16 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_LEVEL, &value))) {
|
2011-04-21 06:29:50 +00:00
|
|
|
if (value >= 0 && value <= 100) {
|
2011-05-11 00:30:20 +00:00
|
|
|
level = FLOAT(value / 100.0);
|
2011-04-21 06:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-12 02:30:16 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_STRUCTURE, &value))) {
|
2011-04-21 06:29:50 +00:00
|
|
|
if (value >= 0 && value <= 2) {
|
|
|
|
geometry = value;
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 02:30:16 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_MODE, &value))) {
|
2011-04-21 06:29:50 +00:00
|
|
|
if (value >= 0 && value <= 5) {
|
|
|
|
mode = value;
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2011-04-21 06:29:50 +00:00
|
|
|
cairo_dwrite_set_cleartype_params(gamma, contrast, level, geometry, mode);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case DWRITE_RENDERING_MODE_ALIASED:
|
|
|
|
case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC:
|
|
|
|
mMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
|
|
|
|
break;
|
|
|
|
case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL:
|
|
|
|
mMeasuringMode = DWRITE_MEASURING_MODE_GDI_NATURAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
|
|
|
|
break;
|
|
|
|
}
|
2012-03-19 19:20:18 +00:00
|
|
|
|
|
|
|
nsRefPtr<IDWriteRenderingParams> defaultRenderingParams;
|
|
|
|
GetDWriteFactory()->CreateRenderingParams(getter_AddRefs(defaultRenderingParams));
|
|
|
|
// For EnhancedContrast, we override the default if the user has not set it
|
|
|
|
// in the registry (by using the ClearType Tuner).
|
|
|
|
if (contrast >= 0.0 && contrast <= 10.0) {
|
2014-08-29 04:18:28 +00:00
|
|
|
contrast = contrast;
|
2012-03-19 19:20:18 +00:00
|
|
|
} else {
|
|
|
|
HKEY hKey;
|
|
|
|
if (RegOpenKeyExA(ENHANCED_CONTRAST_REGISTRY_KEY,
|
|
|
|
0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
contrast = defaultRenderingParams->GetEnhancedContrast();
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
} else {
|
|
|
|
contrast = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For parameters that have not been explicitly set,
|
|
|
|
// we copy values from default params (or our overridden value for contrast)
|
2012-03-19 19:26:17 +00:00
|
|
|
if (gamma < 1.0 || gamma > 2.2) {
|
|
|
|
gamma = defaultRenderingParams->GetGamma();
|
|
|
|
}
|
2012-03-19 19:20:18 +00:00
|
|
|
|
|
|
|
if (level < 0.0 || level > 1.0) {
|
|
|
|
level = defaultRenderingParams->GetClearTypeLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
DWRITE_PIXEL_GEOMETRY dwriteGeometry =
|
|
|
|
static_cast<DWRITE_PIXEL_GEOMETRY>(geometry);
|
|
|
|
DWRITE_RENDERING_MODE renderMode =
|
|
|
|
static_cast<DWRITE_RENDERING_MODE>(mode);
|
|
|
|
|
|
|
|
if (dwriteGeometry < DWRITE_PIXEL_GEOMETRY_FLAT ||
|
|
|
|
dwriteGeometry > DWRITE_PIXEL_GEOMETRY_BGR) {
|
|
|
|
dwriteGeometry = defaultRenderingParams->GetPixelGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (renderMode < DWRITE_RENDERING_MODE_DEFAULT ||
|
|
|
|
renderMode > DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC) {
|
|
|
|
renderMode = defaultRenderingParams->GetRenderingMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
mRenderingParams[TEXT_RENDERING_NO_CLEARTYPE] = defaultRenderingParams;
|
|
|
|
|
|
|
|
GetDWriteFactory()->CreateCustomRenderingParams(gamma, contrast, level,
|
2014-08-29 04:18:28 +00:00
|
|
|
dwriteGeometry, renderMode,
|
2012-03-19 19:20:18 +00:00
|
|
|
getter_AddRefs(mRenderingParams[TEXT_RENDERING_NORMAL]));
|
|
|
|
|
|
|
|
GetDWriteFactory()->CreateCustomRenderingParams(gamma, contrast, level,
|
2014-08-29 04:18:28 +00:00
|
|
|
dwriteGeometry, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC,
|
2012-03-19 19:20:18 +00:00
|
|
|
getter_AddRefs(mRenderingParams[TEXT_RENDERING_GDI_CLASSIC]));
|
2011-04-21 06:29:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:07:56 +00:00
|
|
|
void
|
|
|
|
gfxWindowsPlatform::OnDeviceManagerDestroy(DeviceManagerD3D9* aDeviceManager)
|
|
|
|
{
|
2013-11-21 22:07:57 +00:00
|
|
|
if (aDeviceManager == mDeviceManager) {
|
|
|
|
mDeviceManager = nullptr;
|
|
|
|
}
|
2013-11-21 22:07:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-04 07:46:17 +00:00
|
|
|
IDirect3DDevice9*
|
|
|
|
gfxWindowsPlatform::GetD3D9Device()
|
|
|
|
{
|
|
|
|
DeviceManagerD3D9* manager = GetD3D9DeviceManager();
|
|
|
|
return manager ? manager->device() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManagerD3D9*
|
|
|
|
gfxWindowsPlatform::GetD3D9DeviceManager()
|
|
|
|
{
|
2013-11-21 22:07:57 +00:00
|
|
|
// We should only create the d3d9 device on the compositor thread
|
|
|
|
// or we don't have a compositor thread.
|
|
|
|
if (!mDeviceManager &&
|
2014-06-06 13:51:24 +00:00
|
|
|
(!gfxPlatform::UsesOffMainThreadCompositing() ||
|
|
|
|
CompositorParent::IsInCompositorThread())) {
|
2013-08-04 07:46:17 +00:00
|
|
|
mDeviceManager = new DeviceManagerD3D9();
|
|
|
|
if (!mDeviceManager->Init()) {
|
2015-03-17 14:05:41 +00:00
|
|
|
gfxCriticalError() << "[D3D9] Could not Initialize the DeviceManagerD3D9";
|
2013-08-04 07:46:17 +00:00
|
|
|
mDeviceManager = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDeviceManager;
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:27:09 +00:00
|
|
|
ID3D11Device*
|
|
|
|
gfxWindowsPlatform::GetD3D11Device()
|
|
|
|
{
|
|
|
|
if (mD3D11DeviceInitialized) {
|
|
|
|
return mD3D11Device;
|
|
|
|
}
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
InitD3D11Devices();
|
2013-05-01 14:27:09 +00:00
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
return mD3D11Device;
|
|
|
|
}
|
2013-05-01 14:27:09 +00:00
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
ID3D11Device*
|
|
|
|
gfxWindowsPlatform::GetD3D11ContentDevice()
|
|
|
|
{
|
|
|
|
if (mD3D11DeviceInitialized) {
|
|
|
|
return mD3D11ContentDevice;
|
2013-05-01 14:27:09 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
InitD3D11Devices();
|
2013-05-01 14:27:09 +00:00
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
return mD3D11ContentDevice;
|
2013-05-01 14:27:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:17:13 +00:00
|
|
|
ID3D11Device*
|
|
|
|
gfxWindowsPlatform::GetD3D11MediaDevice()
|
|
|
|
{
|
2015-03-26 00:04:42 +00:00
|
|
|
if (mD3D11MediaDevice) {
|
2015-03-18 21:17:13 +00:00
|
|
|
return mD3D11MediaDevice;
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:04:42 +00:00
|
|
|
if (!mCanInitMediaDevice) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCanInitMediaDevice = false;
|
|
|
|
|
|
|
|
nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll"));
|
|
|
|
decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*)
|
|
|
|
GetProcAddress(d3d11Module, "D3D11CreateDevice");
|
|
|
|
MOZ_ASSERT(d3d11CreateDevice);
|
|
|
|
|
|
|
|
nsTArray<D3D_FEATURE_LEVEL> featureLevels;
|
|
|
|
if (IsWin8OrLater()) {
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
|
|
|
|
}
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
|
|
|
|
|
|
|
|
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
|
|
|
|
MOZ_ASSERT(adapter);
|
|
|
|
|
|
|
|
HRESULT hr = E_INVALIDARG;
|
|
|
|
|
|
|
|
MOZ_SEH_TRY{
|
|
|
|
hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
|
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
|
|
|
|
featureLevels.Elements(), featureLevels.Length(),
|
|
|
|
D3D11_SDK_VERSION, byRef(mD3D11MediaDevice), nullptr, nullptr);
|
|
|
|
} MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
mD3D11MediaDevice = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
d3d11Module.disown();
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mD3D11MediaDevice->SetExceptionMode(0);
|
2015-03-18 21:17:13 +00:00
|
|
|
|
|
|
|
return mD3D11MediaDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:38:46 +00:00
|
|
|
ReadbackManagerD3D11*
|
|
|
|
gfxWindowsPlatform::GetReadbackManager()
|
|
|
|
{
|
|
|
|
if (!mD3D11ReadbackManager) {
|
|
|
|
mD3D11ReadbackManager = new ReadbackManagerD3D11();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mD3D11ReadbackManager;
|
|
|
|
}
|
|
|
|
|
2011-03-02 01:00:33 +00:00
|
|
|
bool
|
|
|
|
gfxWindowsPlatform::IsOptimus()
|
|
|
|
{
|
2014-05-10 16:43:01 +00:00
|
|
|
static int knowIsOptimus = -1;
|
|
|
|
if (knowIsOptimus == -1) {
|
|
|
|
// other potential optimus -- nvd3d9wrapx.dll & nvdxgiwrap.dll
|
|
|
|
if (GetModuleHandleA("nvumdshim.dll") ||
|
|
|
|
GetModuleHandleA("nvumdshimx.dll"))
|
|
|
|
{
|
|
|
|
knowIsOptimus = 1;
|
|
|
|
} else {
|
|
|
|
knowIsOptimus = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return knowIsOptimus;
|
2011-03-02 01:00:33 +00:00
|
|
|
}
|
2013-05-01 14:27:09 +00:00
|
|
|
|
2013-12-18 18:09:10 +00:00
|
|
|
int
|
|
|
|
gfxWindowsPlatform::GetScreenDepth() const
|
|
|
|
{
|
|
|
|
// if the system doesn't have all displays with the same
|
|
|
|
// pixel format, just return 24 and move on with life.
|
|
|
|
if (!GetSystemMetrics(SM_SAMEDISPLAYFORMAT))
|
|
|
|
return 24;
|
|
|
|
|
|
|
|
HDC hdc = GetDC(nullptr);
|
|
|
|
if (!hdc)
|
|
|
|
return 24;
|
|
|
|
|
|
|
|
int depth = GetDeviceCaps(hdc, BITSPIXEL) *
|
|
|
|
GetDeviceCaps(hdc, PLANES);
|
|
|
|
|
|
|
|
ReleaseDC(nullptr, hdc);
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:27:09 +00:00
|
|
|
IDXGIAdapter1*
|
|
|
|
gfxWindowsPlatform::GetDXGIAdapter()
|
|
|
|
{
|
|
|
|
if (mAdapter) {
|
|
|
|
return mAdapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsModuleHandle dxgiModule(LoadLibrarySystem32(L"dxgi.dll"));
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(CreateDXGIFactory1)* createDXGIFactory1 = (decltype(CreateDXGIFactory1)*)
|
2013-05-01 14:27:09 +00:00
|
|
|
GetProcAddress(dxgiModule, "CreateDXGIFactory1");
|
|
|
|
|
|
|
|
// Try to use a DXGI 1.1 adapter in order to share resources
|
|
|
|
// across processes.
|
|
|
|
if (createDXGIFactory1) {
|
|
|
|
nsRefPtr<IDXGIFactory1> factory1;
|
|
|
|
HRESULT hr = createDXGIFactory1(__uuidof(IDXGIFactory1),
|
|
|
|
getter_AddRefs(factory1));
|
|
|
|
|
|
|
|
if (FAILED(hr) || !factory1) {
|
|
|
|
// This seems to happen with some people running the iZ3D driver.
|
|
|
|
// They won't get acceleration.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = factory1->EnumAdapters1(0, byRef(mAdapter));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
// We should return and not accelerate if we can't obtain
|
|
|
|
// an adapter.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We leak this module everywhere, we might as well do so here as well.
|
|
|
|
dxgiModule.disown();
|
|
|
|
|
|
|
|
return mAdapter;
|
|
|
|
}
|
2014-09-14 21:51:27 +00:00
|
|
|
|
2014-11-03 22:55:00 +00:00
|
|
|
bool DoesD3D11DeviceWork(ID3D11Device *device)
|
2014-10-23 04:15:22 +00:00
|
|
|
{
|
|
|
|
static bool checked;
|
|
|
|
static bool result;
|
|
|
|
|
|
|
|
if (checked)
|
|
|
|
return result;
|
|
|
|
checked = true;
|
2014-11-03 22:55:00 +00:00
|
|
|
|
2014-11-12 16:48:01 +00:00
|
|
|
if (gfxPrefs::Direct2DForceEnabled() ||
|
|
|
|
gfxPrefs::LayersAccelerationForceEnabled())
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-03 22:55:00 +00:00
|
|
|
if (GetModuleHandleW(L"dlumd32.dll") && GetModuleHandleW(L"igd10umd32.dll")) {
|
|
|
|
nsString displayLinkModuleVersionString;
|
|
|
|
gfxWindowsPlatform::GetDLLVersion(L"dlumd32.dll", displayLinkModuleVersionString);
|
|
|
|
uint64_t displayLinkModuleVersion;
|
|
|
|
if (!ParseDriverVersion(displayLinkModuleVersionString, &displayLinkModuleVersion)) {
|
2014-11-04 23:17:11 +00:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("DisplayLink: could not parse version\n"));
|
|
|
|
#endif
|
2014-11-03 22:55:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-10 21:11:42 +00:00
|
|
|
if (displayLinkModuleVersion <= V(8,6,1,36484)) {
|
2014-11-04 23:17:11 +00:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("DisplayLink: too old version\n"));
|
|
|
|
#endif
|
2014-11-03 22:55:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-12-22 05:41:57 +00:00
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See bug 1083071. On some drivers, Direct3D 11 CreateShaderResourceView fails
|
|
|
|
// with E_OUTOFMEMORY.
|
|
|
|
bool DoesD3D11TextureSharingWork(ID3D11Device *device)
|
|
|
|
{
|
|
|
|
static bool checked;
|
|
|
|
static bool result;
|
|
|
|
|
|
|
|
if (checked)
|
|
|
|
return result;
|
|
|
|
checked = true;
|
|
|
|
|
|
|
|
if (gfxPrefs::Direct2DForceEnabled() ||
|
|
|
|
gfxPrefs::LayersAccelerationForceEnabled())
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-03 22:55:00 +00:00
|
|
|
|
2015-01-13 20:41:18 +00:00
|
|
|
if (GetModuleHandleW(L"atidxx32.dll")) {
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (gfxInfo) {
|
|
|
|
nsString vendorID, vendorID2;
|
|
|
|
gfxInfo->GetAdapterVendorID(vendorID);
|
|
|
|
gfxInfo->GetAdapterVendorID2(vendorID2);
|
|
|
|
if (vendorID.EqualsLiteral("0x8086") && vendorID2.IsEmpty()) {
|
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("Unexpected Intel/AMD dual-GPU setup\n"));
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:15:22 +00:00
|
|
|
RefPtr<ID3D11Texture2D> texture;
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
2015-01-13 20:41:18 +00:00
|
|
|
desc.Width = 32;
|
|
|
|
desc.Height = 32;
|
2014-10-23 04:15:22 +00:00
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
|
|
|
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
2015-01-13 20:41:18 +00:00
|
|
|
if (FAILED(device->CreateTexture2D(&desc, NULL, byRef(texture)))) {
|
2014-10-23 04:15:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE shareHandle;
|
|
|
|
nsRefPtr<IDXGIResource> otherResource;
|
|
|
|
if (FAILED(texture->QueryInterface(__uuidof(IDXGIResource),
|
|
|
|
getter_AddRefs(otherResource))))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(otherResource->GetSharedHandle(&shareHandle))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ID3D11Resource> sharedResource;
|
|
|
|
nsRefPtr<ID3D11Texture2D> sharedTexture;
|
|
|
|
if (FAILED(device->OpenSharedResource(shareHandle, __uuidof(ID3D11Resource),
|
|
|
|
getter_AddRefs(sharedResource))))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(sharedResource->QueryInterface(__uuidof(ID3D11Texture2D),
|
|
|
|
getter_AddRefs(sharedTexture))))
|
|
|
|
{
|
|
|
|
return false;
|
2014-12-05 07:03:31 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 04:15:22 +00:00
|
|
|
RefPtr<ID3D11ShaderResourceView> sharedView;
|
|
|
|
|
|
|
|
// This if(FAILED()) is the one that actually fails on systems affected by bug 1083071.
|
|
|
|
if (FAILED(device->CreateShaderResourceView(sharedTexture, NULL, byRef(sharedView)))) {
|
2014-12-16 20:50:45 +00:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("CreateShaderResourceView failed\n"));
|
|
|
|
#endif
|
2014-10-23 04:15:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
void
|
|
|
|
gfxWindowsPlatform::InitD3D11Devices()
|
|
|
|
{
|
2014-12-06 00:02:19 +00:00
|
|
|
// This function attempts to initialize our D3D11 devices. If the hardware
|
|
|
|
// is not blacklisted for D3D11 layers. This will first attempt to create a
|
|
|
|
// hardware accelerated device. If this creation fails or the hardware is
|
|
|
|
// blacklisted, then this function will abort if WARP is disabled, causing us
|
|
|
|
// to fallback to D3D9 or Basic layers. If WARP is not disabled it will use
|
|
|
|
// a WARP device which should always be available on Windows 7 and higher.
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
mD3D11DeviceInitialized = true;
|
|
|
|
|
2015-04-01 17:45:58 +00:00
|
|
|
MOZ_ASSERT(!mD3D11Device);
|
|
|
|
|
|
|
|
bool safeMode = false;
|
|
|
|
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
|
|
|
|
if (xr) {
|
|
|
|
xr->GetInSafeMode(&safeMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (safeMode) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-06 00:02:19 +00:00
|
|
|
|
|
|
|
bool useWARP = false;
|
|
|
|
|
2014-10-26 22:46:09 +00:00
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (gfxInfo) {
|
|
|
|
int32_t status;
|
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS, &status))) {
|
|
|
|
if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
|
2014-12-06 00:02:19 +00:00
|
|
|
|
|
|
|
if (gfxPrefs::LayersD3D11DisableWARP()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
useWARP = true;
|
2014-10-26 22:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
if (gfxPrefs::LayersD3D11ForceWARP()) {
|
|
|
|
useWARP = true;
|
|
|
|
}
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll"));
|
|
|
|
decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*)
|
|
|
|
GetProcAddress(d3d11Module, "D3D11CreateDevice");
|
|
|
|
|
|
|
|
if (!d3d11CreateDevice) {
|
2014-12-06 00:02:19 +00:00
|
|
|
// We should just be on Windows Vista or XP in this case.
|
2014-09-14 21:51:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<D3D_FEATURE_LEVEL> featureLevels;
|
|
|
|
if (IsWin8OrLater()) {
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
|
|
|
|
}
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
|
|
|
|
featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
|
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
RefPtr<IDXGIAdapter1> adapter;
|
2014-09-14 21:51:27 +00:00
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
if (!useWARP) {
|
|
|
|
adapter = GetDXGIAdapter();
|
|
|
|
|
|
|
|
if (!adapter) {
|
|
|
|
if (!gfxPrefs::LayersD3D11DisableWARP()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
useWARP = true;
|
|
|
|
}
|
2014-09-14 21:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 20:40:29 +00:00
|
|
|
HRESULT hr = E_INVALIDARG;
|
2014-12-06 00:02:19 +00:00
|
|
|
|
|
|
|
if (!useWARP) {
|
|
|
|
MOZ_SEH_TRY {
|
|
|
|
hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
|
|
|
|
// Use
|
|
|
|
// D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
|
|
|
|
// to prevent bug 1092260. IE 11 also uses this flag.
|
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
|
|
|
|
featureLevels.Elements(), featureLevels.Length(),
|
|
|
|
D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr);
|
|
|
|
} MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
if (gfxPrefs::LayersD3D11DisableWARP()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
useWARP = true;
|
|
|
|
adapter = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-12-22 05:41:57 +00:00
|
|
|
if (FAILED(hr) || !DoesD3D11DeviceWork(mD3D11Device)) {
|
2014-12-06 00:02:19 +00:00
|
|
|
if (gfxPrefs::LayersD3D11DisableWARP()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
useWARP = true;
|
|
|
|
adapter = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useWARP) {
|
|
|
|
MOZ_ASSERT(!gfxPrefs::LayersD3D11DisableWARP());
|
|
|
|
MOZ_ASSERT(!mD3D11Device);
|
|
|
|
MOZ_ASSERT(!adapter);
|
|
|
|
|
2015-04-01 20:44:13 +00:00
|
|
|
ScopedGfxFeatureReporter reporterWARP("D3D11-WARP", gfxPrefs::LayersD3D11ForceWARP());
|
2014-12-06 00:02:19 +00:00
|
|
|
hr = d3d11CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, nullptr,
|
2014-11-24 20:40:29 +00:00
|
|
|
// Use
|
|
|
|
// D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
|
|
|
|
// to prevent bug 1092260. IE 11 also uses this flag.
|
2014-12-06 00:02:19 +00:00
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
|
2014-11-24 20:40:29 +00:00
|
|
|
featureLevels.Elements(), featureLevels.Length(),
|
2014-12-06 00:02:19 +00:00
|
|
|
D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr);
|
2014-09-14 21:51:27 +00:00
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
// This should always succeed... in theory.
|
|
|
|
gfxCriticalError() << "Failed to initialize WARP D3D11 device!" << hr;
|
2015-04-02 18:26:45 +00:00
|
|
|
return;
|
2014-12-06 00:02:19 +00:00
|
|
|
}
|
2015-04-02 18:26:45 +00:00
|
|
|
|
|
|
|
mIsWARP = true;
|
|
|
|
reporterWARP.SetSuccessful();
|
2014-09-14 21:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 15:51:09 +00:00
|
|
|
mD3D11Device->SetExceptionMode(0);
|
|
|
|
|
2014-12-06 00:02:19 +00:00
|
|
|
// We create our device for D2D content drawing here. Normally we don't use
|
|
|
|
// D2D content drawing when using WARP. However when WARP is forced by
|
|
|
|
// default we will let Direct2D use WARP as well.
|
|
|
|
if (Factory::SupportsD2D1() && (!useWARP || gfxPrefs::LayersD3D11ForceWARP())) {
|
|
|
|
MOZ_ASSERT((useWARP && !adapter) || !useWARP);
|
|
|
|
|
2014-11-24 20:40:29 +00:00
|
|
|
hr = E_INVALIDARG;
|
2014-11-27 09:58:26 +00:00
|
|
|
MOZ_SEH_TRY {
|
2014-12-06 00:02:19 +00:00
|
|
|
hr = d3d11CreateDevice(adapter, useWARP ? D3D_DRIVER_TYPE_WARP : D3D_DRIVER_TYPE_UNKNOWN, nullptr,
|
2014-11-24 21:11:24 +00:00
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
|
2014-11-24 20:40:29 +00:00
|
|
|
featureLevels.Elements(), featureLevels.Length(),
|
2014-12-06 00:02:19 +00:00
|
|
|
D3D11_SDK_VERSION, byRef(mD3D11ContentDevice), nullptr, nullptr);
|
2014-11-27 09:58:26 +00:00
|
|
|
} MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
|
2014-12-06 00:02:19 +00:00
|
|
|
mD3D11ContentDevice = nullptr;
|
2014-11-24 20:40:29 +00:00
|
|
|
}
|
2014-09-14 21:51:27 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-12-06 00:02:19 +00:00
|
|
|
d3d11Module.disown();
|
2014-09-14 21:51:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-30 15:51:09 +00:00
|
|
|
mD3D11ContentDevice->SetExceptionMode(0);
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
Factory::SetDirect3D11Device(mD3D11ContentDevice);
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:04:42 +00:00
|
|
|
if (!useWARP) {
|
|
|
|
mCanInitMediaDevice = true;
|
2015-03-18 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 21:51:27 +00:00
|
|
|
// We leak these everywhere and we need them our entire runtime anyway, let's
|
|
|
|
// leak it here as well.
|
|
|
|
d3d11Module.disown();
|
2014-09-17 17:35:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 09:17:26 +00:00
|
|
|
static bool
|
|
|
|
DwmCompositionEnabled()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(WinUtils::dwmIsCompositionEnabledPtr);
|
|
|
|
BOOL dwmEnabled = false;
|
|
|
|
WinUtils::dwmIsCompositionEnabledPtr(&dwmEnabled);
|
|
|
|
return dwmEnabled;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3DVsyncSource final : public VsyncSource
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class D3DVsyncDisplay final : public VsyncSource::Display
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(D3DVsyncDisplay)
|
|
|
|
public:
|
|
|
|
D3DVsyncDisplay()
|
|
|
|
: mVsyncEnabledLock("D3DVsyncEnabledLock")
|
|
|
|
, mVsyncEnabled(false)
|
|
|
|
{
|
|
|
|
mVsyncThread = new base::Thread("WindowsVsyncThread");
|
2015-02-13 09:17:26 +00:00
|
|
|
const double rate = 1000 / 60.0;
|
|
|
|
mSoftwareVsyncRate = TimeDuration::FromMilliseconds(rate);
|
2015-03-12 01:35:50 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mVsyncThread->Start(), "Could not start Windows vsync thread");
|
2015-02-13 09:17:24 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void EnableVsync() override
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-03-12 01:35:50 +00:00
|
|
|
MOZ_ASSERT(mVsyncThread->IsRunning());
|
2015-02-13 09:17:24 +00:00
|
|
|
{ // scope lock
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (mVsyncEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mVsyncEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CancelableTask* vsyncStart = NewRunnableMethod(this,
|
|
|
|
&D3DVsyncDisplay::VBlankLoop);
|
|
|
|
mVsyncThread->message_loop()->PostTask(FROM_HERE, vsyncStart);
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DisableVsync() override
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-03-12 01:35:50 +00:00
|
|
|
MOZ_ASSERT(mVsyncThread->IsRunning());
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (!mVsyncEnabled) {
|
|
|
|
return;
|
2015-02-13 09:17:24 +00:00
|
|
|
}
|
2015-03-12 01:35:50 +00:00
|
|
|
mVsyncEnabled = false;
|
2015-02-13 09:17:24 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsVsyncEnabled() override
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
return mVsyncEnabled;
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:17:26 +00:00
|
|
|
void ScheduleSoftwareVsync(TimeStamp aVsyncTimestamp)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInVsyncThread());
|
|
|
|
NS_WARNING("DwmComposition dynamically disabled, falling back to software timers\n");
|
|
|
|
|
|
|
|
TimeStamp nextVsync = aVsyncTimestamp + mSoftwareVsyncRate;
|
|
|
|
TimeDuration delay = nextVsync - TimeStamp::Now();
|
|
|
|
if (delay.ToMilliseconds() < 0) {
|
|
|
|
delay = mozilla::TimeDuration::FromMilliseconds(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mVsyncThread->message_loop()->PostDelayedTask(FROM_HERE,
|
|
|
|
NewRunnableMethod(this, &D3DVsyncDisplay::VBlankLoop),
|
|
|
|
delay.ToMilliseconds());
|
|
|
|
}
|
|
|
|
|
|
|
|
void VBlankLoop()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInVsyncThread());
|
2015-03-30 15:16:11 +00:00
|
|
|
MOZ_ASSERT(sizeof(int64_t) == sizeof(QPC_TIME));
|
2015-02-13 09:17:26 +00:00
|
|
|
|
|
|
|
DWM_TIMING_INFO vblankTime;
|
|
|
|
// Make sure to init the cbSize, otherwise GetCompositionTiming will fail
|
|
|
|
vblankTime.cbSize = sizeof(DWM_TIMING_INFO);
|
|
|
|
|
|
|
|
LARGE_INTEGER qpcNow;
|
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
TimeStamp vsync = TimeStamp::Now();
|
2015-03-30 15:16:11 +00:00
|
|
|
TimeStamp previousVsync = vsync;
|
2015-02-13 09:17:26 +00:00
|
|
|
const int microseconds = 1000000;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
{ // scope lock
|
|
|
|
MonitorAutoLock lock(mVsyncEnabledLock);
|
|
|
|
if (!mVsyncEnabled) return;
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:16:11 +00:00
|
|
|
if (previousVsync > vsync) {
|
|
|
|
vsync = TimeStamp::Now();
|
|
|
|
NS_WARNING("Previous vsync timestamp is ahead of the calculated vsync timestamp.");
|
|
|
|
}
|
|
|
|
|
|
|
|
previousVsync = vsync;
|
2015-02-13 09:17:26 +00:00
|
|
|
Display::NotifyVsync(vsync);
|
|
|
|
|
|
|
|
// DwmComposition can be dynamically enabled/disabled
|
|
|
|
// so we have to check every time that it's available.
|
|
|
|
// When it is unavailable, we fallback to software but will try
|
|
|
|
// to get back to dwm rendering once it's re-enabled
|
|
|
|
if (!DwmCompositionEnabled()) {
|
|
|
|
ScheduleSoftwareVsync(vsync);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a combination of DwmFlush + DwmGetCompositionTimingInfoPtr
|
|
|
|
// Using WaitForVBlank, the whole system dies :/
|
|
|
|
WinUtils::dwmFlushProcPtr();
|
|
|
|
HRESULT hr = WinUtils::dwmGetCompositionTimingInfoPtr(0, &vblankTime);
|
|
|
|
vsync = TimeStamp::Now();
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
QueryPerformanceCounter(&qpcNow);
|
2015-03-30 15:16:11 +00:00
|
|
|
// Adjust the timestamp to be the vsync timestamp since when
|
|
|
|
// DwmFlush wakes up and when the actual vsync occurred are not the
|
|
|
|
// same.
|
|
|
|
int64_t adjust = qpcNow.QuadPart - vblankTime.qpcVBlank;
|
|
|
|
int64_t usAdjust = (adjust * microseconds) / frequency.QuadPart;
|
2015-02-13 09:17:26 +00:00
|
|
|
vsync -= TimeDuration::FromMicroseconds((double) usAdjust);
|
|
|
|
}
|
|
|
|
} // end for
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:17:24 +00:00
|
|
|
private:
|
2015-02-23 11:14:49 +00:00
|
|
|
virtual ~D3DVsyncDisplay()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
DisableVsync();
|
2015-03-12 01:35:50 +00:00
|
|
|
mVsyncThread->Stop();
|
2015-02-23 11:14:49 +00:00
|
|
|
delete mVsyncThread;
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:17:24 +00:00
|
|
|
bool IsInVsyncThread()
|
|
|
|
{
|
|
|
|
return mVsyncThread->thread_id() == PlatformThread::CurrentId();
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:17:26 +00:00
|
|
|
TimeDuration mSoftwareVsyncRate;
|
2015-02-13 09:17:24 +00:00
|
|
|
Monitor mVsyncEnabledLock;
|
|
|
|
base::Thread* mVsyncThread;
|
|
|
|
bool mVsyncEnabled;
|
|
|
|
}; // end d3dvsyncdisplay
|
|
|
|
|
|
|
|
D3DVsyncSource()
|
|
|
|
{
|
|
|
|
mPrimaryDisplay = new D3DVsyncDisplay();
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual Display& GetGlobalDisplay() override
|
2015-02-13 09:17:24 +00:00
|
|
|
{
|
|
|
|
return *mPrimaryDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~D3DVsyncSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
nsRefPtr<D3DVsyncDisplay> mPrimaryDisplay;
|
|
|
|
}; // end D3DVsyncSource
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxWindowsPlatform::CreateHardwareVsyncSource()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (!WinUtils::dwmIsCompositionEnabledPtr) {
|
|
|
|
NS_WARNING("Dwm composition not available, falling back to software vsync\n");
|
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL dwmEnabled = false;
|
|
|
|
WinUtils::dwmIsCompositionEnabledPtr(&dwmEnabled);
|
|
|
|
if (!dwmEnabled) {
|
|
|
|
NS_WARNING("DWM not enabled, falling back to software vsync\n");
|
|
|
|
return gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<VsyncSource> d3dVsyncSource = new D3DVsyncSource();
|
|
|
|
return d3dVsyncSource.forget();
|
|
|
|
}
|
2015-03-24 22:04:44 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
gfxWindowsPlatform::SupportsApzTouchInput()
|
|
|
|
{
|
|
|
|
int value = Preferences::GetInt("dom.w3c_touch_events.enabled", 0);
|
|
|
|
return value == 1 || value == 2;
|
|
|
|
}
|