From 749af957555d28fb497d95b392e68c7a98274d98 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Wed, 3 Nov 2010 12:43:29 +1300 Subject: [PATCH] Bug 584259 - Add support for StereoMode element. r=roc a=roc --- content/media/nsBuiltinDecoderReader.cpp | 1 + content/media/nsBuiltinDecoderReader.h | 4 +++ content/media/webm/nsWebMReader.cpp | 42 ++++++++++++++++++++++++ gfx/layers/ImageLayers.h | 9 +++++ gfx/layers/d3d9/ImageLayerD3D9.cpp | 38 +++++++++++++++------ gfx/layers/d3d9/LayerManagerD3D9.cpp | 7 ---- gfx/layers/d3d9/LayerManagerD3D9.h | 8 ----- gfx/layers/d3d9/Nv3DVUtils.cpp | 4 +-- gfx/layers/d3d9/Nv3DVUtils.h | 18 +++++----- modules/libpref/src/init/all.js | 2 -- 10 files changed, 95 insertions(+), 38 deletions(-) diff --git a/content/media/nsBuiltinDecoderReader.cpp b/content/media/nsBuiltinDecoderReader.cpp index 0b8c68c1d20..00734074bdc 100644 --- a/content/media/nsBuiltinDecoderReader.cpp +++ b/content/media/nsBuiltinDecoderReader.cpp @@ -148,6 +148,7 @@ VideoData* VideoData::Create(nsVideoInfo& aInfo, data.mPicX = aInfo.mPicture.x; data.mPicY = aInfo.mPicture.y; data.mPicSize = gfxIntSize(aInfo.mPicture.width, aInfo.mPicture.height); + data.mStereoMode = aInfo.mStereoMode; videoImage->SetData(data); // Copies buffer return v.forget(); diff --git a/content/media/nsBuiltinDecoderReader.h b/content/media/nsBuiltinDecoderReader.h index b121ec2f909..0a2412fa3ae 100644 --- a/content/media/nsBuiltinDecoderReader.h +++ b/content/media/nsBuiltinDecoderReader.h @@ -59,6 +59,7 @@ public: mAudioRate(0), mAudioChannels(0), mFrame(0,0), + mStereoMode(mozilla::layers::STEREO_MODE_MONO), mHasAudio(PR_FALSE), mHasVideo(PR_FALSE) {} @@ -82,6 +83,9 @@ public: // Used to seek to the start of the media. PRInt64 mDataOffset; + // Indicates the frame layout for single track stereo videos. + mozilla::layers::StereoMode mStereoMode; + // PR_TRUE if we have an active audio bitstream. PRPackedBool mHasAudio; diff --git a/content/media/webm/nsWebMReader.cpp b/content/media/webm/nsWebMReader.cpp index 5d50b094d7a..26dbc9a749c 100644 --- a/content/media/webm/nsWebMReader.cpp +++ b/content/media/webm/nsWebMReader.cpp @@ -43,8 +43,11 @@ #include "nsWebMReader.h" #include "VideoUtils.h" #include "nsTimeRanges.h" +#include "nsIServiceManager.h" +#include "nsIPrefService.h" using namespace mozilla; +using namespace mozilla::layers; // Un-comment to enable logging of seek bisections. //#define SEEK_LOGGING @@ -268,6 +271,45 @@ nsresult nsWebMReader::ReadMetadata() mInfo.mPicture.height = params.height; } + switch (params.stereo_mode) { + case NESTEGG_VIDEO_MONO: + mInfo.mStereoMode = STEREO_MODE_MONO; + break; + case NESTEGG_VIDEO_STEREO_LEFT_RIGHT: + mInfo.mStereoMode = STEREO_MODE_LEFT_RIGHT; + break; + case NESTEGG_VIDEO_STEREO_BOTTOM_TOP: + mInfo.mStereoMode = STEREO_MODE_BOTTOM_TOP; + break; + case NESTEGG_VIDEO_STEREO_TOP_BOTTOM: + mInfo.mStereoMode = STEREO_MODE_TOP_BOTTOM; + break; + case NESTEGG_VIDEO_STEREO_RIGHT_LEFT: + mInfo.mStereoMode = STEREO_MODE_RIGHT_LEFT; + break; + } + + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + PRInt32 forceStereoMode; + if (NS_SUCCEEDED(prefs->GetIntPref("media.webm.force_stereo_mode", &forceStereoMode))) { + switch (forceStereoMode) { + case 1: + mInfo.mStereoMode = STEREO_MODE_LEFT_RIGHT; + break; + case 2: + mInfo.mStereoMode = STEREO_MODE_RIGHT_LEFT; + break; + case 3: + mInfo.mStereoMode = STEREO_MODE_TOP_BOTTOM; + break; + case 4: + mInfo.mStereoMode = STEREO_MODE_BOTTOM_TOP; + break; + default: + mInfo.mStereoMode = STEREO_MODE_MONO; + } + } + // mDataOffset is not used by the WebM backend. // See bug 566779 for a suggestion to refactor // and remove it. diff --git a/gfx/layers/ImageLayers.h b/gfx/layers/ImageLayers.h index 2045c5db474..b031157ee93 100644 --- a/gfx/layers/ImageLayers.h +++ b/gfx/layers/ImageLayers.h @@ -46,6 +46,14 @@ namespace mozilla { namespace layers { +enum StereoMode { + STEREO_MODE_MONO, + STEREO_MODE_LEFT_RIGHT, + STEREO_MODE_RIGHT_LEFT, + STEREO_MODE_BOTTOM_TOP, + STEREO_MODE_TOP_BOTTOM +}; + /** * A class representing a buffer of pixel data. The data can be in one * of various formats including YCbCr. @@ -277,6 +285,7 @@ public: PRUint32 mPicX; PRUint32 mPicY; gfxIntSize mPicSize; + StereoMode mStereoMode; }; enum { diff --git a/gfx/layers/d3d9/ImageLayerD3D9.cpp b/gfx/layers/d3d9/ImageLayerD3D9.cpp index e969c57120c..38f0b15e901 100644 --- a/gfx/layers/d3d9/ImageLayerD3D9.cpp +++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp @@ -176,17 +176,35 @@ ImageLayerD3D9::RenderLayer() mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER); - /* - * Send 3d control data and metadata - */ - if (mD3DManager->Is3DEnabled() && mD3DManager->GetNv3DVUtils()) { - mD3DManager->GetNv3DVUtils()->SendNv3DVControl(STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE); + if (yuvImage->mData.mStereoMode != STEREO_MODE_MONO) { + Nv_Stereo_Mode mode; + switch (yuvImage->mData.mStereoMode) { + case STEREO_MODE_LEFT_RIGHT: + mode = NV_STEREO_MODE_LEFT_RIGHT; + break; + case STEREO_MODE_RIGHT_LEFT: + mode = NV_STEREO_MODE_RIGHT_LEFT; + break; + case STEREO_MODE_BOTTOM_TOP: + mode = NV_STEREO_MODE_BOTTOM_TOP; + break; + case STEREO_MODE_TOP_BOTTOM: + mode = NV_STEREO_MODE_TOP_BOTTOM; + break; + } - nsRefPtr renderTarget; - device()->GetRenderTarget(0, getter_AddRefs(renderTarget)); - mD3DManager->GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->mSize.width, - (unsigned int)yuvImage->mSize.height, (HANDLE)(yuvImage->mYTexture), (HANDLE)(renderTarget)); - } + /* + * Send 3d control data and metadata + */ + if (mD3DManager->GetNv3DVUtils()) { + mD3DManager->GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE); + + nsRefPtr renderTarget; + device()->GetRenderTarget(0, getter_AddRefs(renderTarget)); + mD3DManager->GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->mSize.width, + (unsigned int)yuvImage->mSize.height, (HANDLE)(yuvImage->mYTexture), (HANDLE)(renderTarget)); + } + } device()->SetTexture(0, yuvImage->mYTexture); device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); diff --git a/gfx/layers/d3d9/LayerManagerD3D9.cpp b/gfx/layers/d3d9/LayerManagerD3D9.cpp index e59c15f819a..59b595b821f 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9.cpp +++ b/gfx/layers/d3d9/LayerManagerD3D9.cpp @@ -42,8 +42,6 @@ #include "ImageLayerD3D9.h" #include "ColorLayerD3D9.h" #include "CanvasLayerD3D9.h" -#include "nsIServiceManager.h" -#include "nsIPrefService.h" #include "gfxWindowsPlatform.h" #include "nsIGfxInfo.h" @@ -57,7 +55,6 @@ namespace layers { DeviceManagerD3D9 *LayerManagerD3D9::mDefaultDeviceManager = nsnull; LayerManagerD3D9::LayerManagerD3D9(nsIWidget *aWidget) - : mIs3DEnabled(PR_FALSE) { mWidget = aWidget; mCurrentCallbackInfo.Callback = NULL; @@ -72,10 +69,6 @@ LayerManagerD3D9::~LayerManagerD3D9() PRBool LayerManagerD3D9::Initialize() { - /* Check the user preference for whether 3d video is enabled or not */ - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - prefs->GetBoolPref("gfx.3d_video.enabled", &mIs3DEnabled); - nsCOMPtr gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); if (gfxInfo) { PRInt32 status; diff --git a/gfx/layers/d3d9/LayerManagerD3D9.h b/gfx/layers/d3d9/LayerManagerD3D9.h index 6ee0b939d9b..c476cca03d7 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9.h +++ b/gfx/layers/d3d9/LayerManagerD3D9.h @@ -175,11 +175,6 @@ public: */ Nv3DVUtils *GetNv3DVUtils() { return mDeviceManager ? mDeviceManager->GetNv3DVUtils() : NULL; } - /** - * Indicate whether 3D is enabled or not - */ - PRBool Is3DEnabled() { return mIs3DEnabled; } - static void OnDeviceManagerDestroy(DeviceManagerD3D9 *aDeviceManager) { if(aDeviceManager == mDefaultDeviceManager) mDefaultDeviceManager = nsnull; @@ -212,9 +207,6 @@ private: /* Callback info for current transaction */ CallbackInfo mCurrentCallbackInfo; - /* Flag that indicates whether 3D is enabled or not*/ - PRBool mIs3DEnabled; - /* * Region we're clipping our current drawing to. */ diff --git a/gfx/layers/d3d9/Nv3DVUtils.cpp b/gfx/layers/d3d9/Nv3DVUtils.cpp index 8e44a23c169..93376d101bc 100644 --- a/gfx/layers/d3d9/Nv3DVUtils.cpp +++ b/gfx/layers/d3d9/Nv3DVUtils.cpp @@ -133,7 +133,7 @@ Nv3DVUtils::SetDeviceInfo(IUnknown *devUnknown) if (!rv) return; - rv = m3DVStreaming->Nv3DVControl(STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE); + rv = m3DVStreaming->Nv3DVControl(NV_STEREO_MODE_RIGHT_LEFT, true, FIREFOX_3DV_APP_HANDLE); NS_ASSERTION(rv, "Nv3DVStreaming Nv3DVControl failed!"); } @@ -142,7 +142,7 @@ Nv3DVUtils::SetDeviceInfo(IUnknown *devUnknown) * calls from ImageLayerD3D9 to the 3DV COM object */ void -Nv3DVUtils::SendNv3DVControl(Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) +Nv3DVUtils::SendNv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) { if (!m3DVStreaming) return; diff --git a/gfx/layers/d3d9/Nv3DVUtils.h b/gfx/layers/d3d9/Nv3DVUtils.h index 6aae9e95407..1aab221bf74 100644 --- a/gfx/layers/d3d9/Nv3DVUtils.h +++ b/gfx/layers/d3d9/Nv3DVUtils.h @@ -47,13 +47,13 @@ namespace layers { #define FIREFOX_3DV_APP_HANDLE 0xECB992B6 -typedef enum _Stereo_Mode { - STEREO_MODE_LEFT_RIGHT = 0, - STEREO_MODE_RIGHT_LEFT = 1, - STEREO_MODE_TOP_BOTTOM = 2, - STEREO_MODE_BOTTOM_TOP = 3, - STEREO_MODE_LAST = 4 -} Stereo_Mode; +enum Nv_Stereo_Mode { + NV_STEREO_MODE_LEFT_RIGHT = 0, + NV_STEREO_MODE_RIGHT_LEFT = 1, + NV_STEREO_MODE_TOP_BOTTOM = 2, + NV_STEREO_MODE_BOTTOM_TOP = 3, + NV_STEREO_MODE_LAST = 4 +}; class INv3DVStreaming : public IUnknown { @@ -61,7 +61,7 @@ public: virtual bool Nv3DVInitialize() = 0; virtual bool Nv3DVRelease() = 0; virtual bool Nv3DVSetDevice(IUnknown* pDevice) = 0; - virtual bool Nv3DVControl(Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) = 0; + virtual bool Nv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle) = 0; virtual bool Nv3DVMetaData(DWORD dwWidth, DWORD dwHeight, HANDLE hSrcLuma, HANDLE hDst) = 0; }; @@ -95,7 +95,7 @@ public: * Send Stereo Control Information. Used mainly to re-route * calls from ImageLayerD3D9 to the 3DV COM object */ - void SendNv3DVControl(Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle); + void SendNv3DVControl(Nv_Stereo_Mode eStereoMode, bool bEnableStereo, DWORD dw3DVAppHandle); /* * Send Stereo Metadata. Used mainly to re-route calls diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 4eba5704c2a..364f7cdffe8 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -189,8 +189,6 @@ pref("gfx.color_management.mode", 2); pref("gfx.color_management.display_profile", ""); pref("gfx.color_management.rendering_intent", 0); -pref("gfx.3d_video.enabled", false); - pref("gfx.downloadable_fonts.enabled", true); pref("gfx.downloadable_fonts.sanitize", true); #ifdef XP_MACOSX