Skip to content

Commit

Permalink
Add an NPN_GetValue query to find the browser's DXGI adapter. (bug 12…
Browse files Browse the repository at this point in the history
…17665 part 10, r=aklotz,mattwoodrow)
  • Loading branch information
David Anderson committed Dec 2, 2015
1 parent 93ddc75 commit ff85d25
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 6 deletions.
1 change: 1 addition & 0 deletions dom/plugins/base/npapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ typedef enum {
, NPNVsupportsAsyncBitmapSurfaceBool = 2007
#if defined(XP_WIN)
, NPNVsupportsAsyncWindowsDXGISurfaceBool = 2008
, NPNVpreferredDXGIAdapter = 2009
#endif
#if defined(XP_MACOSX)
#ifndef NP_NO_CARBON
Expand Down
3 changes: 3 additions & 0 deletions dom/plugins/ipc/PPluginInstance.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using mozilla::plugins::WindowsSharedMemoryHandle from "mozilla/plugins/PluginMe
using mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
using nsIntRect from "nsRect.h";
using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
using struct DxgiAdapterDesc from "mozilla/D3DMessageUtils.h";

namespace mozilla {
namespace plugins {
Expand Down Expand Up @@ -153,6 +154,8 @@ parent:
returns (bool value);
intr NPN_GetValue_SupportsAsyncDXGISurface()
returns (bool value);
intr NPN_GetValue_PreferredDXGIAdapter()
returns (DxgiAdapterDesc desc);

intr NPN_SetValue_NPPVpluginWindow(bool windowed)
returns (NPError result);
Expand Down
13 changes: 13 additions & 0 deletions dom/plugins/ipc/PluginInstanceChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include "gfxXlibSurface.h"
#endif
#ifdef XP_WIN
#include "mozilla/D3DMessageUtils.h"
#include "mozilla/gfx/SharedDIBSurface.h"
#include "nsCrashOnException.h"
#include "gfxWindowsPlatform.h"
extern const wchar_t* kFlashFullscreenClass;
using mozilla::gfx::SharedDIBSurface;
#endif
Expand Down Expand Up @@ -459,6 +461,17 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
}
#endif

#ifdef XP_WIN
case NPNVpreferredDXGIAdapter: {
DxgiAdapterDesc desc;
if (!CallNPN_GetValue_PreferredDXGIAdapter(&desc)) {
return NPERR_GENERIC_ERROR;
}
*reinterpret_cast<DXGI_ADAPTER_DESC*>(aValue) = desc.ToDesc();
return NPERR_NO_ERROR;
}
#endif

#ifdef XP_MACOSX
case NPNVsupportsCoreGraphicsBool: {
*((NPBool*)aValue) = true;
Expand Down
33 changes: 33 additions & 0 deletions dom/plugins/ipc/PluginInstanceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,39 @@ PluginInstanceParent::AnswerNPN_GetValue_SupportsAsyncDXGISurface(bool* value)
return true;
}

bool
PluginInstanceParent::AnswerNPN_GetValue_PreferredDXGIAdapter(DxgiAdapterDesc* aOutDesc)
{
PodZero(aOutDesc);
#ifdef XP_WIN
if (!AllowDirectDXGISurfaceDrawing()) {
return false;
}

ID3D11Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D11ContentDevice();
if (!device) {
return false;
}

RefPtr<IDXGIDevice> dxgi;
if (FAILED(device->QueryInterface(__uuidof(IDXGIDevice), getter_AddRefs(dxgi))) || !dxgi) {
return false;
}
RefPtr<IDXGIAdapter> adapter;
if (FAILED(dxgi->GetAdapter(getter_AddRefs(adapter))) || !adapter) {
return false;
}

DXGI_ADAPTER_DESC desc;
if (FAILED(adapter->GetDesc(&desc))) {
return false;
}

*aOutDesc = DxgiAdapterDesc::From(desc);
#endif
return true;
}

bool
PluginInstanceParent::AnswerNPN_SetValue_NPPVpluginWindow(
const bool& windowed, NPError* result)
Expand Down
3 changes: 3 additions & 0 deletions dom/plugins/ipc/PluginInstanceParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class PluginInstanceParent : public PPluginInstanceParent
virtual bool
AnswerNPN_GetValue_SupportsAsyncDXGISurface(bool* value) override;

virtual bool
AnswerNPN_GetValue_PreferredDXGIAdapter(DxgiAdapterDesc* desc) override;

virtual bool
AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result) override;
virtual bool
Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/test/testplugin/nptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ NPP_SetWindow(NPP instance, NPWindow* window)

#if defined(XP_WIN)
if (instanceData->asyncDrawing == AD_DXGI) {
if (!setupDxgiSurfaces(instanceData)) {
if (!setupDxgiSurfaces(instance, instanceData)) {
return NPERR_GENERIC_ERROR;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/test/testplugin/nptest.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef struct InstanceData {
void notifyDidPaint(InstanceData* instanceData);

#if defined(XP_WIN)
bool setupDxgiSurfaces(InstanceData* instanceData);
bool setupDxgiSurfaces(NPP npp, InstanceData* instanceData);
void drawDxgiBitmapColor(InstanceData* instanceData);
#endif

Expand Down
37 changes: 33 additions & 4 deletions dom/plugins/test/testplugin/nptest_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,39 @@ typedef HRESULT (WINAPI*D2D1CreateFactoryFunc)(
void **factory
);

static IDXGIAdapter1*
FindDXGIAdapter(NPP npp, IDXGIFactory1* factory)
{
DXGI_ADAPTER_DESC preferred;
if (NPN_GetValue(npp, NPNVpreferredDXGIAdapter, &preferred) != NPERR_NO_ERROR) {
return nullptr;
}

UINT index = 0;
for (;;) {
IDXGIAdapter1* adapter = nullptr;
if (FAILED(factory->EnumAdapters1(index, &adapter)) || !adapter) {
return nullptr;
}

DXGI_ADAPTER_DESC desc;
if (SUCCEEDED(adapter->GetDesc(&desc)) &&
desc.AdapterLuid.LowPart == preferred.AdapterLuid.LowPart &&
desc.AdapterLuid.HighPart == preferred.AdapterLuid.HighPart &&
desc.VendorId == preferred.VendorId &&
desc.DeviceId == preferred.DeviceId)
{
return adapter;
}

adapter->Release();
index++;
}
}

// Note: we leak modules since we need them anyway.
bool
setupDxgiSurfaces(InstanceData* instanceData)
setupDxgiSurfaces(NPP npp, InstanceData* instanceData)
{
HMODULE dxgi = LoadLibraryA("dxgi.dll");
if (!dxgi) {
Expand All @@ -125,9 +155,8 @@ setupDxgiSurfaces(InstanceData* instanceData)
return false;
}

hr = factory1->EnumAdapters1(0, &instanceData->platformData->adapter);
factory1->Release();
if (FAILED(hr) || !instanceData->platformData->adapter) {
instanceData->platformData->adapter = FindDXGIAdapter(npp, factory1);
if (!instanceData->platformData->adapter) {
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions gfx/ipc/D3DMessageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ DxgiAdapterDesc::From(const DXGI_ADAPTER_DESC& aDesc)
{
return reinterpret_cast<const DxgiAdapterDesc&>(aDesc);
}

const DXGI_ADAPTER_DESC&
DxgiAdapterDesc::ToDesc() const
{
return reinterpret_cast<const DXGI_ADAPTER_DESC&>(*this);
}
#endif

namespace IPC {
Expand Down
1 change: 1 addition & 0 deletions gfx/ipc/D3DMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct DxgiAdapterDesc
LUID AdapterLuid;

static const DxgiAdapterDesc& From(const DXGI_ADAPTER_DESC& aDesc);
const DXGI_ADAPTER_DESC& ToDesc() const;
#endif

bool operator ==(const DxgiAdapterDesc& aOther) const;
Expand Down

0 comments on commit ff85d25

Please sign in to comment.