Bug 648484, part 5: Create our D3D10 device so as to allow cross-process resource sharing. r=Bas
authorChris Jones <jones.chris.g@gmail.com>
Tue, 09 Aug 2011 12:38:26 -0700
changeset 74135 9f8e7494989a229aa24582a27a2a33db2c2fb07e
parent 74134 d04af79b34ae49286c60bf6b35db0ada7daa07f4
child 74136 5a136975b5bcfbeeb76e4d8d11b484bc8a853b1b
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersBas
bugs648484
milestone8.0a1
Bug 648484, part 5: Create our D3D10 device so as to allow cross-process resource sharing. r=Bas
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -74,16 +74,17 @@
 #include <string>
 
 using namespace mozilla::gfx;
 
 #ifdef CAIRO_HAS_D2D_SURFACE
 #include "gfxD2DSurface.h"
 
 #include <d3d10_1.h>
+#include <dxgi.h>
 
 #include "mozilla/gfx/2D.h"
 
 #include "nsIMemoryReporter.h"
 #include "nsMemory.h"
 #endif
 
 using namespace mozilla;
@@ -147,16 +148,21 @@ typedef HRESULT (WINAPI*D3D10CreateDevic
   IDXGIAdapter *pAdapter,
   D3D10_DRIVER_TYPE DriverType,
   HMODULE Software,
   UINT Flags,
   D3D10_FEATURE_LEVEL1 HardwareLevel,
   UINT SDKVersion,
   ID3D10Device1 **ppDevice
 );
+
+typedef HRESULT(WINAPI*CreateDXGIFactory1Func)(
+  REFIID riid,
+  void **ppFactory
+);
 #endif
 
 static __inline void
 BuildKeyNameFromFontName(nsAString &aName)
 {
     if (aName.Length() >= LF_FACESIZE)
         aName.Truncate(LF_FACESIZE - 1);
     ToLowerCase(aName);
@@ -313,36 +319,60 @@ gfxWindowsPlatform::VerifyD2DDevice(PRBo
     mozilla::ScopedGfxFeatureReporter reporter("D2D");
 
     HMODULE d3d10module = LoadLibraryA("d3d10_1.dll");
     D3D10CreateDevice1Func createD3DDevice = (D3D10CreateDevice1Func)
         GetProcAddress(d3d10module, "D3D10CreateDevice1");
     nsRefPtr<ID3D10Device1> device;
 
     if (createD3DDevice) {
+        HMODULE dxgiModule = LoadLibraryA("dxgi.dll");
+        CreateDXGIFactory1Func createDXGIFactory1 = (CreateDXGIFactory1Func)
+            GetProcAddress(dxgiModule, "CreateDXGIFactory1");
+
+        // Try to use a DXGI 1.1 adapter in order to share resources
+        // across processes.
+        nsRefPtr<IDXGIAdapter1> adapter1;
+        if (createDXGIFactory1) {
+            nsRefPtr<IDXGIFactory1> factory1;
+            HRESULT hr = createDXGIFactory1(__uuidof(IDXGIFactory1),
+                                            getter_AddRefs(factory1));
+    
+            nsRefPtr<IDXGIAdapter1> adapter1; 
+            hr = factory1->EnumAdapters1(0, getter_AddRefs(adapter1));
+
+            if (SUCCEEDED(hr) && adapter1) {
+                hr = adapter1->CheckInterfaceSupport(__uuidof(ID3D10Device1),
+                                                     nsnull);
+                if (FAILED(hr)) {
+                    adapter1 = nsnull;
+                }
+            }
+        }
+
         // We try 10.0 first even though we prefer 10.1, since we want to
         // fail as fast as possible if 10.x isn't supported.
         HRESULT hr = createD3DDevice(
-            NULL, 
+            adapter1, 
             D3D10_DRIVER_TYPE_HARDWARE,
             NULL,
             D3D10_CREATE_DEVICE_BGRA_SUPPORT |
             D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
             D3D10_FEATURE_LEVEL_10_0,
             D3D10_1_SDK_VERSION,
             getter_AddRefs(device));
 
         if (SUCCEEDED(hr)) {
             // We have 10.0, let's try 10.1.
             // XXX - This adds an additional 10-20ms for people who are
             // getting direct2d. We'd really like to do something more
             // clever.
             nsRefPtr<ID3D10Device1> device1;
             hr = createD3DDevice(
-                NULL, 
+                adapter1, 
                 D3D10_DRIVER_TYPE_HARDWARE,
                 NULL,
                 D3D10_CREATE_DEVICE_BGRA_SUPPORT |
                 D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
                 D3D10_FEATURE_LEVEL_10_1,
                 D3D10_1_SDK_VERSION,
                 getter_AddRefs(device1));