michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/DebugOnly.h" michael@0: michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIConsoleService.h" michael@0: #include michael@0: #include "Nv3DVUtils.h" michael@0: michael@0: DEFINE_GUID(CLSID_NV3DVStreaming, michael@0: 0xf7747266, 0x777d, 0x4f61, 0xa1, 0x75, 0xdd, 0x5a, 0xdf, 0x1e, 0x37, 0xdf); michael@0: michael@0: DEFINE_GUID(IID_INV3DVStreaming, michael@0: 0xf98f9bb2, 0xb914, 0x4d44, 0x98, 0xfa, 0x6e, 0x37, 0x85, 0x16, 0x98, 0x55); michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: /** michael@0: * Constructor and Destructor michael@0: */ michael@0: Nv3DVUtils::Nv3DVUtils() michael@0: : m3DVStreaming (nullptr) michael@0: { michael@0: } michael@0: michael@0: Nv3DVUtils::~Nv3DVUtils() michael@0: { michael@0: UnInitialize(); michael@0: } michael@0: michael@0: michael@0: // Silence spurious warnings! michael@0: #if defined(WARNING) || defined WARN_IF_FALSE michael@0: #error We shouldn't be redefining these! michael@0: #endif michael@0: // Uncomment these to enable spurious warnings. michael@0: //#define WARNING(str) NS_WARNING(str) michael@0: //#define WARN_IF_FALSE(b, str) NS_WARN_IF_FALSE(b, str) michael@0: #define WARNING(str) michael@0: #define WARN_IF_FALSE(b, str) michael@0: michael@0: /** michael@0: * Initializes the Nv3DVUtils object. michael@0: */ michael@0: void michael@0: Nv3DVUtils::Initialize() michael@0: { michael@0: /* michael@0: * Detect if 3D Streaming object is already loaded. Do nothing in that case. michael@0: */ michael@0: if (m3DVStreaming) { michael@0: WARNING("Nv3DVStreaming COM object already instantiated.\n"); michael@0: return; michael@0: } michael@0: michael@0: /* michael@0: * Create the COM object. If we fail at any stage, just return michael@0: */ michael@0: HRESULT hr = CoCreateInstance(CLSID_NV3DVStreaming, nullptr, CLSCTX_INPROC_SERVER, IID_INV3DVStreaming, (void**)(getter_AddRefs(m3DVStreaming))); michael@0: if (FAILED(hr) || !m3DVStreaming) { michael@0: WARNING("Nv3DVStreaming CoCreateInstance failed (disabled)."); michael@0: return; michael@0: } michael@0: michael@0: /* michael@0: * Initialize the object. Note that m3DVStreaming cannot be nullptr at this point. michael@0: */ michael@0: bool bRetVal = m3DVStreaming->Nv3DVInitialize(); michael@0: michael@0: if (!bRetVal) { michael@0: WARNING("Nv3DVStreaming Nv3DVInitialize failed!"); michael@0: return; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Release resources used by the COM Object, and then release michael@0: * the COM Object (nsRefPtr gets released by setting to nullptr) michael@0: * michael@0: */ michael@0: void michael@0: Nv3DVUtils::UnInitialize() michael@0: { michael@0: if (m3DVStreaming) { michael@0: m3DVStreaming->Nv3DVRelease(); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Sets the device info, along with any other initialization that is needed after device creation michael@0: * Pass the D3D9 device pointer is an IUnknown input argument. michael@0: */ michael@0: void michael@0: Nv3DVUtils::SetDeviceInfo(IUnknown *devUnknown) michael@0: { michael@0: if (!devUnknown) { michael@0: WARNING("D3D Device Pointer (IUnknown) is nullptr.\n"); michael@0: return; michael@0: } michael@0: michael@0: if (!m3DVStreaming) { michael@0: return; michael@0: } michael@0: michael@0: bool rv = m3DVStreaming->Nv3DVSetDevice(devUnknown); michael@0: if (!rv) { michael@0: WARNING("Nv3DVStreaming Nv3DVControl failed!"); michael@0: return; michael@0: } michael@0: michael@0: rv = m3DVStreaming->Nv3DVControl(NV_STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE); michael@0: WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!"); michael@0: } michael@0: michael@0: /* michael@0: * Send Stereo Control Information. Used mainly to re-route michael@0: * calls from ImageLayerD3D9 to the 3DV COM object michael@0: */ michael@0: void michael@0: Nv3DVUtils::SendNv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) michael@0: { michael@0: if (!m3DVStreaming) michael@0: return; michael@0: michael@0: DebugOnly rv = m3DVStreaming->Nv3DVControl(eStereoMode, bEnableStereo, dw3DVAppHandle); michael@0: WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!"); michael@0: } michael@0: michael@0: /* michael@0: * Send Stereo Metadata. Used mainly to re-route calls michael@0: * from ImageLayerD3D9 to the 3DV COM object michael@0: */ michael@0: void michael@0: Nv3DVUtils::SendNv3DVMetaData(unsigned int dwWidth, unsigned int dwHeight, HANDLE hSrcLuma, HANDLE hDst) michael@0: { michael@0: if (!m3DVStreaming) michael@0: return; michael@0: michael@0: DebugOnly rv = m3DVStreaming->Nv3DVMetaData((DWORD)dwWidth, (DWORD)dwHeight, hSrcLuma, hDst); michael@0: WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVMetaData failed!"); michael@0: } michael@0: michael@0: } /* namespace layers */ michael@0: } /* namespace mozilla */