Bug 1180246 - Part 3 - remove usage of cairo_d2d_device. r=bas
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -69,17 +69,17 @@ ContentClient::CreateContentClient(Compo
backend != LayersBackend::LAYERS_BASIC) {
return nullptr;
}
bool useDoubleBuffering = false;
#ifdef XP_WIN
if (backend == LayersBackend::LAYERS_D3D11) {
- useDoubleBuffering = !!gfxWindowsPlatform::GetPlatform()->GetD2DDevice();
+ useDoubleBuffering = !!gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
} else
#endif
#ifdef MOZ_WIDGET_GTK
// We can't use double buffering when using image content with
// Xrender support on Linux, as ContentHostDoubleBuffered is not
// suited for direct uploads to the server.
if (!gfxPlatformGtk::GetPlatform()->UseImageOffscreenSurfaces() ||
!gfxPlatformGtk::GetPlatform()->UseXRender())
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -339,17 +339,17 @@ TextureClient::CreateForDrawing(ISurface
int32_t maxTextureSize = aAllocator->GetMaxTextureSize();
#endif
#ifdef XP_WIN
LayersBackend parentBackend = aAllocator->GetCompositorBackendType();
if (parentBackend == LayersBackend::LAYERS_D3D11 &&
(aMoz2DBackend == gfx::BackendType::DIRECT2D ||
aMoz2DBackend == gfx::BackendType::DIRECT2D1_1) &&
- gfxWindowsPlatform::GetPlatform()->GetD2DDevice() &&
+ gfxWindowsPlatform::GetPlatform()->GetD3D10Device() &&
aSize.width <= maxTextureSize &&
aSize.height <= maxTextureSize) {
texture = new TextureClientD3D11(aAllocator, aFormat, aTextureFlags);
}
if (parentBackend == LayersBackend::LAYERS_D3D9 &&
aMoz2DBackend == gfx::BackendType::CAIRO &&
aAllocator->IsSameProcess() &&
aSize.width <= maxTextureSize &&
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -382,19 +382,16 @@ gfxWindowsPlatform::gfxWindowsPlatform()
mUsingGDIFonts = false;
/*
* Initialize COM
*/
CoInitialize(nullptr);
-#ifdef CAIRO_HAS_D2D_SURFACE
- mD2DDevice = nullptr;
-#endif
RegisterStrongMemoryReporter(new GfxD2DVramReporter());
if (gfxPrefs::Direct2DUse1_1()) {
InitD3D11Devices();
}
UpdateRenderMode();
@@ -403,28 +400,21 @@ gfxWindowsPlatform::gfxWindowsPlatform()
RegisterStrongMemoryReporter(new D3D9TextureReporter());
RegisterStrongMemoryReporter(new D3D9SurfaceImageReporter());
RegisterStrongMemoryReporter(new D3D9SharedTextureReporter());
}
gfxWindowsPlatform::~gfxWindowsPlatform()
{
mDeviceManager = nullptr;
+ mD3D10Device = nullptr;
mD3D11Device = nullptr;
mD3D11ContentDevice = nullptr;
mD3D11ImageBridgeDevice = nullptr;
- // 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
-
mozilla::gfx::Factory::D2DCleanup();
mAdapter = nullptr;
/*
* Uninitialize COM
*/
CoUninitialize();
@@ -508,22 +498,22 @@ gfxWindowsPlatform::UpdateRenderMode()
tryD2D = false;
}
ID3D11Device *device = GetD3D11Device();
if (isVistaOrHigher && !InSafeMode() && tryD2D && device &&
mDoesD3D11TextureSharingWork) {
VerifyD2DDevice(d2dForceEnabled);
- if (mD2DDevice && GetD3D11Device()) {
+ if (mD3D10Device && GetD3D11Device()) {
mRenderMode = RENDER_DIRECT2D;
mUseDirectWrite = true;
}
} else {
- mD2DDevice = nullptr;
+ mD3D10Device = nullptr;
}
#endif
#ifdef CAIRO_HAS_DWRITE_FONT
// Enable when it's preffed on -and- we're using Vista or higher. Or when
// we're going to use D2D.
if (!mDWriteFactory && (mUseDirectWrite && isVistaOrHigher)) {
mozilla::ScopedGfxFeatureReporter reporter("DWrite");
@@ -591,34 +581,37 @@ gfxWindowsPlatform::CreateDevice(nsRefPt
nsModuleHandle d3d10module(LoadLibrarySystem32(L"d3d10_1.dll"));
if (!d3d10module)
return E_FAIL;
decltype(D3D10CreateDevice1)* createD3DDevice =
(decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module, "D3D10CreateDevice1");
if (!createD3DDevice)
return E_FAIL;
- nsRefPtr<ID3D10Device1> device;
+ ID3D10Device1* device = nullptr;
HRESULT hr =
createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr,
#ifdef DEBUG
// This isn't set because of bug 1078411
// D3D10_CREATE_DEVICE_DEBUG |
#endif
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));
+ D3D10_1_SDK_VERSION, &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);
+ mD3D10Device = device;
+
+ // Leak the module while the D3D 10 device is being used.
+ d3d10module.disown();
// Setup a pref for future launch optimizaitons when in main process.
if (XRE_IsParentProcess()) {
Preferences::SetInt(kFeatureLevelPref, featureLevelIndex);
}
}
return device ? S_OK : hr;
@@ -629,33 +622,29 @@ void
gfxWindowsPlatform::VerifyD2DDevice(bool aAttemptForce)
{
#ifdef CAIRO_HAS_D2D_SURFACE
DriverInitCrashDetection detectCrashes;
if (detectCrashes.DisableAcceleration()) {
return;
}
- if (mD2DDevice) {
- ID3D10Device1 *device = cairo_d2d_device_get_device(mD2DDevice);
-
- if (SUCCEEDED(device->GetDeviceRemovedReason())) {
+ if (mD3D10Device) {
+ if (SUCCEEDED(mD3D10Device->GetDeviceRemovedReason())) {
return;
}
- mD2DDevice = nullptr;
+ mD3D10Device = nullptr;
// Surface cache needs to be invalidated since it may contain vector
// images rendered with our old, broken D2D device.
SurfaceCache::DiscardAll();
}
mozilla::ScopedGfxFeatureReporter reporter("D2D", aAttemptForce);
- nsRefPtr<ID3D10Device1> device;
-
int supportedFeatureLevelsCount = ArrayLength(kSupportedFeatureLevels);
nsRefPtr<IDXGIAdapter1> adapter1 = GetDXGIAdapter();
if (!adapter1) {
// Unable to create adapter, abort acceleration.
return;
}
@@ -684,23 +673,19 @@ gfxWindowsPlatform::VerifyD2DDevice(bool
hr = CreateDevice(adapter1, i);
// If it failed then we don't have new hardware
if (FAILED(hr)) {
break;
}
}
}
- if (!mD2DDevice && aAttemptForce) {
- mD2DDevice = cairo_d2d_create_device();
- }
-
- if (mD2DDevice) {
+ if (mD3D10Device) {
reporter.SetSuccessful();
- mozilla::gfx::Factory::SetDirect3D10Device(cairo_d2d_device_get_device(mD2DDevice));
+ mozilla::gfx::Factory::SetDirect3D10Device(mD3D10Device);
}
ScopedGfxFeatureReporter reporter1_1("D2D1.1");
if (Factory::SupportsD2D1()) {
reporter1_1.SetSuccessful();
}
#endif
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -235,20 +235,17 @@ public:
IDWriteRenderingParams *GetRenderingParams(TextRenderingMode aRenderMode)
{ return mRenderingParams[aRenderMode]; }
#else
inline bool DWriteEnabled() { return false; }
#endif
void OnDeviceManagerDestroy(mozilla::layers::DeviceManagerD3D9* aDeviceManager);
mozilla::layers::DeviceManagerD3D9* GetD3D9DeviceManager();
IDirect3DDevice9* GetD3D9Device();
-#ifdef CAIRO_HAS_D2D_SURFACE
- cairo_device_t *GetD2DDevice() { return mD2DDevice; }
- ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; }
-#endif
+ ID3D10Device1 *GetD3D10Device() { return mD3D10Device; }
ID3D11Device *GetD3D11Device();
ID3D11Device *GetD3D11ContentDevice();
// Device to be used on the ImageBridge thread
ID3D11Device *GetD3D11ImageBridgeDevice();
// Create a D3D11 device to be used for DXVA decoding.
already_AddRefed<ID3D11Device> CreateD3D11DecoderDevice();
@@ -286,21 +283,19 @@ private:
bool mUsingGDIFonts;
#ifdef CAIRO_HAS_DWRITE_FONT
nsRefPtr<IDWriteFactory> mDWriteFactory;
nsRefPtr<IDWriteTextAnalyzer> mDWriteAnalyzer;
nsRefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
DWRITE_MEASURING_MODE mMeasuringMode;
#endif
-#ifdef CAIRO_HAS_D2D_SURFACE
- cairo_device_t *mD2DDevice;
-#endif
mozilla::RefPtr<IDXGIAdapter1> mAdapter;
nsRefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
+ mozilla::RefPtr<ID3D10Device1> mD3D10Device;
mozilla::RefPtr<ID3D11Device> mD3D11Device;
mozilla::RefPtr<ID3D11Device> mD3D11ContentDevice;
mozilla::RefPtr<ID3D11Device> mD3D11ImageBridgeDevice;
bool mD3D11DeviceInitialized;
mozilla::RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
bool mIsWARP;
bool mHasDeviceReset;
bool mDoesD3D11TextureSharingWork;