gfx/layers/d3d9/Nv3DVUtils.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/d3d9/Nv3DVUtils.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/DebugOnly.h"
    1.10 +
    1.11 +#include "nsIServiceManager.h"
    1.12 +#include "nsIConsoleService.h"
    1.13 +#include <initguid.h>
    1.14 +#include "Nv3DVUtils.h"
    1.15 +
    1.16 +DEFINE_GUID(CLSID_NV3DVStreaming, 
    1.17 +0xf7747266, 0x777d, 0x4f61, 0xa1, 0x75, 0xdd, 0x5a, 0xdf, 0x1e, 0x37, 0xdf);
    1.18 +
    1.19 +DEFINE_GUID(IID_INV3DVStreaming, 
    1.20 +0xf98f9bb2, 0xb914, 0x4d44, 0x98, 0xfa, 0x6e, 0x37, 0x85, 0x16, 0x98, 0x55);
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace layers {
    1.24 +
    1.25 +/**
    1.26 + * Constructor and Destructor
    1.27 + */
    1.28 +Nv3DVUtils::Nv3DVUtils()
    1.29 +  : m3DVStreaming (nullptr)
    1.30 +{
    1.31 +}
    1.32 +
    1.33 +Nv3DVUtils::~Nv3DVUtils()
    1.34 +{
    1.35 +  UnInitialize();
    1.36 +}
    1.37 +
    1.38 +
    1.39 +// Silence spurious warnings!
    1.40 +#if defined(WARNING) || defined WARN_IF_FALSE
    1.41 +#error We shouldn't be redefining these!
    1.42 +#endif
    1.43 +// Uncomment these to enable spurious warnings.
    1.44 +//#define WARNING(str) NS_WARNING(str)
    1.45 +//#define WARN_IF_FALSE(b, str) NS_WARN_IF_FALSE(b, str)
    1.46 +#define WARNING(str)
    1.47 +#define WARN_IF_FALSE(b, str)
    1.48 +
    1.49 +/**
    1.50 + * Initializes the Nv3DVUtils object.
    1.51 + */
    1.52 +void
    1.53 +Nv3DVUtils::Initialize()
    1.54 +{
    1.55 +  /*
    1.56 +   * Detect if 3D Streaming object is already loaded. Do nothing in that case.
    1.57 +   */
    1.58 +  if (m3DVStreaming) {
    1.59 +    WARNING("Nv3DVStreaming COM object already instantiated.\n");
    1.60 +    return;
    1.61 +  }
    1.62 +
    1.63 +  /*
    1.64 +   * Create the COM object. If we fail at any stage, just return
    1.65 +   */
    1.66 +  HRESULT hr = CoCreateInstance(CLSID_NV3DVStreaming, nullptr, CLSCTX_INPROC_SERVER, IID_INV3DVStreaming, (void**)(getter_AddRefs(m3DVStreaming)));
    1.67 +  if (FAILED(hr) || !m3DVStreaming) {
    1.68 +    WARNING("Nv3DVStreaming CoCreateInstance failed (disabled).");
    1.69 +    return;
    1.70 +  }
    1.71 +
    1.72 +  /*
    1.73 +   * Initialize the object. Note that m3DVStreaming cannot be nullptr at this point.
    1.74 +   */
    1.75 +  bool bRetVal = m3DVStreaming->Nv3DVInitialize();
    1.76 +
    1.77 +  if (!bRetVal) {
    1.78 +    WARNING("Nv3DVStreaming Nv3DVInitialize failed!");
    1.79 +    return;
    1.80 +  }
    1.81 +}
    1.82 +
    1.83 +/**
    1.84 + * Release resources used by the COM Object, and then release 
    1.85 + * the COM Object (nsRefPtr gets released by setting to nullptr) 
    1.86 + *
    1.87 + */
    1.88 +void
    1.89 +Nv3DVUtils::UnInitialize()
    1.90 +{
    1.91 +  if (m3DVStreaming) {
    1.92 +    m3DVStreaming->Nv3DVRelease();
    1.93 +  }
    1.94 +}
    1.95 +
    1.96 +/**
    1.97 + * Sets the device info, along with any other initialization that is needed after device creation
    1.98 + * Pass the D3D9 device pointer is an IUnknown input argument.
    1.99 + */
   1.100 +void 
   1.101 +Nv3DVUtils::SetDeviceInfo(IUnknown *devUnknown)
   1.102 +{
   1.103 +  if (!devUnknown) {
   1.104 +    WARNING("D3D Device Pointer (IUnknown) is nullptr.\n");
   1.105 +    return;
   1.106 +  }
   1.107 +
   1.108 +  if (!m3DVStreaming) {
   1.109 +      return;
   1.110 +  }
   1.111 +
   1.112 +  bool rv = m3DVStreaming->Nv3DVSetDevice(devUnknown);
   1.113 +  if (!rv) {
   1.114 +      WARNING("Nv3DVStreaming Nv3DVControl failed!");
   1.115 +      return;
   1.116 +  }
   1.117 +
   1.118 +  rv = m3DVStreaming->Nv3DVControl(NV_STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE);
   1.119 +  WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!");
   1.120 +}
   1.121 +
   1.122 +/*
   1.123 + * Send Stereo Control Information. Used mainly to re-route
   1.124 + * calls from ImageLayerD3D9 to the 3DV COM object
   1.125 + */
   1.126 +void 
   1.127 +Nv3DVUtils::SendNv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle)
   1.128 +{
   1.129 +  if (!m3DVStreaming)
   1.130 +      return;
   1.131 +
   1.132 +  DebugOnly<bool> rv = m3DVStreaming->Nv3DVControl(eStereoMode, bEnableStereo, dw3DVAppHandle);
   1.133 +  WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVControl failed!");
   1.134 +}
   1.135 +
   1.136 +/*
   1.137 + * Send Stereo Metadata. Used mainly to re-route calls
   1.138 + * from ImageLayerD3D9 to the 3DV COM object
   1.139 + */
   1.140 +void
   1.141 +Nv3DVUtils::SendNv3DVMetaData(unsigned int dwWidth, unsigned int dwHeight, HANDLE hSrcLuma, HANDLE hDst)
   1.142 +{
   1.143 +  if (!m3DVStreaming)
   1.144 +      return;
   1.145 +
   1.146 +  DebugOnly<bool> rv = m3DVStreaming->Nv3DVMetaData((DWORD)dwWidth, (DWORD)dwHeight, hSrcLuma, hDst);
   1.147 +  WARN_IF_FALSE(rv, "Nv3DVStreaming Nv3DVMetaData failed!");
   1.148 +}
   1.149 +
   1.150 +} /* namespace layers */
   1.151 +} /* namespace mozilla */

mercurial