Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/DebugOnly.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIServiceManager.h" |
michael@0 | 9 | #include "nsIConsoleService.h" |
michael@0 | 10 | #include <initguid.h> |
michael@0 | 11 | #include "Nv3DVUtils.h" |
michael@0 | 12 | |
michael@0 | 13 | DEFINE_GUID(CLSID_NV3DVStreaming, |
michael@0 | 14 | 0xf7747266, 0x777d, 0x4f61, 0xa1, 0x75, 0xdd, 0x5a, 0xdf, 0x1e, 0x37, 0xdf); |
michael@0 | 15 | |
michael@0 | 16 | DEFINE_GUID(IID_INV3DVStreaming, |
michael@0 | 17 | 0xf98f9bb2, 0xb914, 0x4d44, 0x98, 0xfa, 0x6e, 0x37, 0x85, 0x16, 0x98, 0x55); |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace layers { |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * Constructor and Destructor |
michael@0 | 24 | */ |
michael@0 | 25 | Nv3DVUtils::Nv3DVUtils() |
michael@0 | 26 | : m3DVStreaming (nullptr) |
michael@0 | 27 | { |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | Nv3DVUtils::~Nv3DVUtils() |
michael@0 | 31 | { |
michael@0 | 32 | UnInitialize(); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | |
michael@0 | 36 | // Silence spurious warnings! |
michael@0 | 37 | #if defined(WARNING) || defined WARN_IF_FALSE |
michael@0 | 38 | #error We shouldn't be redefining these! |
michael@0 | 39 | #endif |
michael@0 | 40 | // Uncomment these to enable spurious warnings. |
michael@0 | 41 | //#define WARNING(str) NS_WARNING(str) |
michael@0 | 42 | //#define WARN_IF_FALSE(b, str) NS_WARN_IF_FALSE(b, str) |
michael@0 | 43 | #define WARNING(str) |
michael@0 | 44 | #define WARN_IF_FALSE(b, str) |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Initializes the Nv3DVUtils object. |
michael@0 | 48 | */ |
michael@0 | 49 | void |
michael@0 | 50 | Nv3DVUtils::Initialize() |
michael@0 | 51 | { |
michael@0 | 52 | /* |
michael@0 | 53 | * Detect if 3D Streaming object is already loaded. Do nothing in that case. |
michael@0 | 54 | */ |
michael@0 | 55 | if (m3DVStreaming) { |
michael@0 | 56 | WARNING("Nv3DVStreaming COM object already instantiated.\n"); |
michael@0 | 57 | return; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | * Create the COM object. If we fail at any stage, just return |
michael@0 | 62 | */ |
michael@0 | 63 | HRESULT hr = CoCreateInstance(CLSID_NV3DVStreaming, nullptr, CLSCTX_INPROC_SERVER, IID_INV3DVStreaming, (void**)(getter_AddRefs(m3DVStreaming))); |
michael@0 | 64 | if (FAILED(hr) || !m3DVStreaming) { |
michael@0 | 65 | WARNING("Nv3DVStreaming CoCreateInstance failed (disabled)."); |
michael@0 | 66 | return; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | /* |
michael@0 | 70 | * Initialize the object. Note that m3DVStreaming cannot be nullptr at this point. |
michael@0 | 71 | */ |
michael@0 | 72 | bool bRetVal = m3DVStreaming->Nv3DVInitialize(); |
michael@0 | 73 | |
michael@0 | 74 | if (!bRetVal) { |
michael@0 | 75 | WARNING("Nv3DVStreaming Nv3DVInitialize failed!"); |
michael@0 | 76 | return; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Release resources used by the COM Object, and then release |
michael@0 | 82 | * the COM Object (nsRefPtr gets released by setting to nullptr) |
michael@0 | 83 | * |
michael@0 | 84 | */ |
michael@0 | 85 | void |
michael@0 | 86 | Nv3DVUtils::UnInitialize() |
michael@0 | 87 | { |
michael@0 | 88 | if (m3DVStreaming) { |
michael@0 | 89 | m3DVStreaming->Nv3DVRelease(); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Sets the device info, along with any other initialization that is needed after device creation |
michael@0 | 95 | * Pass the D3D9 device pointer is an IUnknown input argument. |
michael@0 | 96 | */ |
michael@0 | 97 | void |
michael@0 | 98 | Nv3DVUtils::SetDeviceInfo(IUnknown *devUnknown) |
michael@0 | 99 | { |
michael@0 | 100 | if (!devUnknown) { |
michael@0 | 101 | WARNING("D3D Device Pointer (IUnknown) is nullptr.\n"); |
michael@0 | 102 | return; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | if (!m3DVStreaming) { |
michael@0 | 106 | return; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | bool rv = m3DVStreaming->Nv3DVSetDevice(devUnknown); |
michael@0 | 110 | if (!rv) { |
michael@0 | 111 | WARNING("Nv3DVStreaming Nv3DVControl failed!"); |
michael@0 | 112 | return; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | rv = m3DVStreaming->Nv3DVControl(NV_STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE); |
michael@0 | 116 | WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!"); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | /* |
michael@0 | 120 | * Send Stereo Control Information. Used mainly to re-route |
michael@0 | 121 | * calls from ImageLayerD3D9 to the 3DV COM object |
michael@0 | 122 | */ |
michael@0 | 123 | void |
michael@0 | 124 | Nv3DVUtils::SendNv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) |
michael@0 | 125 | { |
michael@0 | 126 | if (!m3DVStreaming) |
michael@0 | 127 | return; |
michael@0 | 128 | |
michael@0 | 129 | DebugOnly<bool> rv = m3DVStreaming->Nv3DVControl(eStereoMode, bEnableStereo, dw3DVAppHandle); |
michael@0 | 130 | WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!"); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | /* |
michael@0 | 134 | * Send Stereo Metadata. Used mainly to re-route calls |
michael@0 | 135 | * from ImageLayerD3D9 to the 3DV COM object |
michael@0 | 136 | */ |
michael@0 | 137 | void |
michael@0 | 138 | Nv3DVUtils::SendNv3DVMetaData(unsigned int dwWidth, unsigned int dwHeight, HANDLE hSrcLuma, HANDLE hDst) |
michael@0 | 139 | { |
michael@0 | 140 | if (!m3DVStreaming) |
michael@0 | 141 | return; |
michael@0 | 142 | |
michael@0 | 143 | DebugOnly<bool> rv = m3DVStreaming->Nv3DVMetaData((DWORD)dwWidth, (DWORD)dwHeight, hSrcLuma, hDst); |
michael@0 | 144 | WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVMetaData failed!"); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | } /* namespace layers */ |
michael@0 | 148 | } /* namespace mozilla */ |