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>
Wed, 13 Jul 2011 22:43:43 -0700
changeset 72806 817d86d378cfaea8f9815674ce5208d51f45a2c2
parent 72805 00dd5138b32d7f5f0f87f966881cf2a62244ab7f
child 72807 ce033bf153b66f70ac3a185e3276a872eb2a0fc3
push id20772
push usereakhgari@mozilla.com
push dateThu, 14 Jul 2011 16:20:50 +0000
treeherdermozilla-central@89b5fccb0514 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs648484
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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));